Python Forum
python 3.x comparing variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python 3.x comparing variables
#1
Why doesn't this work in Python 3.x?
quarters = input('How many quarters do you have? ')
if quarters <= 8:
    print ('You need more money.')
I get this error from the original program here.
Error:
Traceback (most recent call last): File "house.py", line 118, in <module> front_porch() File "house.py", line 21, in front_porch living_room() File "house.py", line 106, in living_room basement() File "house.py", line 67, in basement if quarters <= 8: TypeError: '<=' not supported between instances of 'str' and 'int'
Reply
#2
change:
quarters = input('How many quarters do you have? ')
to
quarters = int(input('How many quarters do you have? '))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  A more efficient way of comparing two images in a python vukan 0 2,025 Mar-17-2020, 11:39 AM
Last Post: vukan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020