Python: Program error? (Beginner) -


this question has answer here:

i learning python first time(complete beginner) , have make program:

in store products have discounts depending on code:

• products code 45612 have 10% discount

• products code 45613 have 12% discount

• products code 45614 have 18% discount

• products code 45615 have 20% discount

write algorithm reads code (int) , value (float) product , calculate price after discount.

if code have entered doesn't exist, should print "the password not right.

but program doesn't work, doing wrong?

this code:

kodikos = [45612, 45613, 45614, 45615]  password = input("give code: ")  timi = float(input("give price: "))    if password == 45612:       timi = timi - 10      print("the price after discount %f" %(timi))  if password == 45613:       timi = timi - 12      print("the price after discount %f" %(timi))  if password == 45614:       timi = timi - 18      print("the price after discount %f" %(timi))  if password == 45615:       timi = timi - 20      print("the price after discount %f" %(timi))   n in kodikos:       if(n != password):          print("the password doesn't exist!")          break 

you subtract fixed amount must subtract relative amout (i.e. 10 per cent of value). try code:

kodikos = [45612, 45613, 45614, 45615]  password = input("give code: ")  timi = float(input("give price: "))    if password == 45612:       timi = timi - 0.1 * timi      print("the price after discount %f" %(timi))  if password == 45613:       timi = timi - 0.12 * timi      print("the price after discount %f" %(timi))  if password == 45614:       timi = timi - 0.18 * timi      print("the price after discount %f" %(timi))  if password == 45615:       timi = timi - 0.2 * timi      print("the price after discount %f" %(timi))   n in kodikos:       if(n != password):          print("the password doesn't exist!")          break 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -