educative.io

Educative

Why I got an incorrect code

Hello,
this is my code for this exercise

price=250

if(price>=300):
discount=price * 0.3
elif(price<300 and price>=200):
discount=price * 0.2
elif(price<200 and price>=100):
discount=price * 0.1
elif(price<100 and price>=0):
discount=price * 0.05
else:
discount=0

print(price - discount)

The exercise wants you to assign the variable price to the new value based on the discount. So at the end of your program, instead of printing the price after the discount, assign the the price after the discount to the variable price.

Let me know if this helps!

well hate to be the one to correct but

that one work
price = 250

if price < 0:
print(“Invalid price. No discount will be applied.”)
elif price < 100:
discounted = (5/100) * price
price = price - discounted
print("There will be a 5% discount and the new price is ", price)
elif price >= 100 and price < 200:
discounted = (10/100) * price
price = price - discounted
print("There will be a 10% discount and the new price is ", price)
elif price >= 200 and price < 300:
discounted = (20/100) * price
price = price - discounted
print("There will be a 20% discount and the new price is ", price)
else:
discounted = (30/100) * price
price = price - discounted
print("There will be a 30% discount and the new price is ", price)