Ask coding questions

← Back to all posts
Mega sales
RadhikaGupta1 (0)

Can anyone tell me why my line 4 isn't working. Every time I type in anything more than 20 it still comes up with a one pound voucher.

Commentshotnewtop
pyelias (931)

money > 10 <= 20 means money > 10 and 10 <= 20. You might have meant 10 < money <= 20.

OmniShift (12)

mcuringa's solution is probably best, but what you were probably aiming for was:
if money > 10 and money <= 20:

Note the 'and' keyword and the fact that we compare 20 to money again (in a second condition, the variable is not implied; it needs to be stated again, because computers just aren't as smart as people when it comes to this :P)

mcuringa (2)

If you test the "20" condition first, it fixes your problem and makes the logic simpler and easier to read.

money = float(input("How much money have you spent today?"))
if money > 20:
  print ("you are entitled to a 3 pound voucher to spend next time you come in the store")
elif money > 10:
  print ("you are now entitled to a 1 pound voucher to spend next time you come in the Store")
else:
  print ("Have a nice day.")
leon332157 (69)

You can change it to:
if money >10:
• if money <=20:
•• print()
• elif money >20:
•• print()
Because, it won’t work in one line if u want to compare money>10 and =>20.