0

So this is the problem section in a simple "Is your amount greater than or less than 50?" program. This section is entirely independent, but it doesn't work. If my input is 50 or anything less, it says "Sorry, not enough money." But strangely, from 100 and on, it also registers those amounts as "Sorry, that is not enough money." I've tried a bunch of things with it and I can't get it to work! What am I missing? Thank you!

money_amount = input("Type your amount with no quotations.")

if money_amount <= "50":
    print ("Sorry, that is not enough money.")
    quit()

else:
    print ("Yay!")
Brad Solomon
  • 38,521
  • 31
  • 149
  • 235

3 Answers3

0

As @Brad Solomon suggests, you need to convert the value into a number (integer) before you can do reasonable mathematical comparisons.

So here is a simple solution:

money_amount = input("Type your amount with no quotations.")
money_amount = int(money_amount)

if money_amount <= 50:
    print ("Sorry, that is not enough money.")
    quit()

else:
    print ("Yay!")
Mike Williamson
  • 4,915
  • 14
  • 67
  • 104
0

You can't compare an string and an integer and expect good results. You should transform the input in an integer using int().

money_amount = int(input("Type your amount with no quotations."))

if money_amount <= 50:
    print ("Sorry, that is not enough money.")
    quit()

else:
    print ("Yay!")

By that way you can convert a string into a number to make the comparison. "50" from input would be transform into 50.

Also, you can't make an math operation (<=) with strings. So if money_amount <= "50": should be changed to if money_amount <= 50: (from string to integer), by that way you would be able to compare both numbers.

Ender Look
  • 2,303
  • 2
  • 17
  • 41
0

Or you can try this one:

money_amount = int(raw_input("Type your amount with no quotations."))
if money_amount <= 50:
     print ("Sorry, that is not enough money.")
     quit()
else:
     print ("Yay!")
Mike
  • 185
  • 1
  • 9