Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't get this....
#2
Hello, next time please post code in Python code tags, this time I added them for you.

A lot is missing in the code, Python is smart but it cannot read your mind :)

As things are now, your input gets "lost" after you enter age. Instead you need to store it in a variable (e.g. "age"):
age = int(input('please indicate your_age. '))
If statement will return True or False, based on result of the evaluation. if 20: Will always evaluate to True, that is why you always get same result. Instead you need something like this:
if age <= 20:
    print('sorry. you are not yet qualified to vote.')
elif age > 20: 
    print ('good. please proceed to the voting booth.')
Take some time to read the docs on IF and other Python statements.

Stick with Python 3, Python 2 support is ending), Python 3 is the future.

Edit:

In the additional code you posted, your_age is first assigned 20 and then 21, and remains so for the rest of the program. In this case the elif statement evaluates to True (your_age is 21, which is greater or equal than 21), so you always get same result. Again, whatever input you give it doesn't get stored anywhere.

And another thing, input returns you a string, so if you want to compare the integer values, you need to convert it with int().

Edit2:

Quote:there has to be a variable when getting input..........a python quirk, where python will only evaluate zero (0) as false, and everything else is evaluated to true
These are correct.
Reply


Messages In This Thread
I don't get this.... - by pancit_canton - Jan-26-2018, 12:12 PM
RE: I don't get this.... - by j.crater - Jan-26-2018, 12:20 PM
RE: I don't get this.... - by pancit_canton - Jan-26-2018, 12:57 PM
RE: I don't get this.... - by wavic - Jan-26-2018, 06:11 PM

Forum Jump:

User Panel Messages

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