Project 29: E-commerce Cart
Python Challenge
Builds on these lessons
Step 1 of 3
Project
Reading a Secret Key Safely
Read a payment provider's API key with os.environ["PAYMENT_API_KEY"] — never hardcoded as a string literal in the file. A key committed into source control is compromised the moment it's pushed, even if the line is deleted later; git history keeps it forever.
🎯 Your Task
Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!
import os
payment_api_key = os.environ["PAYMENT_API_KEY"]
def checkout(cart_total):
print(f"Charging ${cart_total} using key ending in ...{payment_api_key[-4:]}")
checkout(42.00)