+ 2

How would you make a voting test

when the person enter their age and the test either says they are of age or not 18 to vote

23rd May 2017, 6:07 PM
Talia Pacelli
Talia Pacelli - avatar
12 odpowiedzi
+ 10
age = eval(input()) if age >= 18 and age != "": print("You can vote") else: print("You can't vote") #You should add more controls, this is just a basic start # I hope this is not your homework ^_^
23rd May 2017, 6:13 PM
Maz
Maz - avatar
+ 9
age = int(input("enter your age: ")) //inputs age print(age) //prints value of age print("#######################\n") if age >= 18: //checks age to see if voting possible print("You can vote") else: print("You must at least 18 to vote") //Code by Wisdom
23rd May 2017, 6:40 PM
Pixie
Pixie - avatar
+ 9
First declare the age and secondly testing for the value of age. Take Sololearn Python course to understand better.
23rd May 2017, 6:47 PM
Wisdom Abioye
Wisdom Abioye - avatar
23rd May 2017, 6:15 PM
Pixie
Pixie - avatar
+ 8
With the Python's course. =^=
23rd May 2017, 6:17 PM
Maz
Maz - avatar
+ 6
You need the age because you're testing for it. Without the age you wouldn't know whether the user is eligible to vote or not.
23rd May 2017, 6:34 PM
Wisdom Abioye
Wisdom Abioye - avatar
23rd May 2017, 6:24 PM
Wisdom Abioye
Wisdom Abioye - avatar
+ 3
This gives me a great idea thank you
23rd May 2017, 6:16 PM
Talia Pacelli
Talia Pacelli - avatar
+ 3
I'm very new to it, don't want the exact code. just want to know where to start
23rd May 2017, 6:17 PM
Talia Pacelli
Talia Pacelli - avatar
+ 1
I am thank you. Everyone I see a new code it's just nice to understand.. I have some basics down.
23rd May 2017, 6:49 PM
Talia Pacelli
Talia Pacelli - avatar
0
why is it that I need AND AGE in that code? I was able to run it but is someone able to explain. for future purposes?
23rd May 2017, 6:28 PM
Talia Pacelli
Talia Pacelli - avatar
0
I get that, but why is age in the code twice?
23rd May 2017, 6:36 PM
Talia Pacelli
Talia Pacelli - avatar