Skip to content

Instantly share code, notes, and snippets.

@abraham-ny
Created May 13, 2025 17:27
Show Gist options
  • Select an option

  • Save abraham-ny/a77b3b4e04732da29c381600afe1705e to your computer and use it in GitHub Desktop.

Select an option

Save abraham-ny/a77b3b4e04732da29c381600afe1705e to your computer and use it in GitHub Desktop.
PLP-Week3-Python-Assignment (.env and other files not submitted in this gist)
def calculate_discount(price, discount_percent):
# Check if the discount is 20% or more
if discount_percent >= 20:
# Calculate the discounted price
discount_amount = (discount_percent / 100) * price
final_price = price - discount_amount
return final_price
else:
# Return the original price if discount is less than 20%
return price
try:
original_price = float(input("Enter the original price of the item: $"))
discount_percentage = float(input("Enter the discount percentage: "))
final_price = calculate_discount(original_price, discount_percentage)
if final_price < original_price:
print(f"Discount applied! The final price is: ${final_price:.2f}")
else:
print(f"No discount applied. The price remains: ${original_price:.2f}")
except ValueError:
print("Invalid input. Please enter a valid number for price and discount percentage.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment