Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I check if a number is greater than another number, then store it as a variable

I have the python code that asks the question about the users age, but I also need it to check if the user is above 18 and then store if they are 18 or not in a variable.

I have the basic age = int(input('What is your age?: '))
set up but now I need it to check if the user is above 18 and then to store a yes or no type of value, as in yes they are above 18 or no that they arent, then I would need to print an acceptance or denial, no if they are not 18 or above and yes if they are.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

accepted = 'yes' if int(input('What is your age?: ')) >= 18 else 'no'
print(accepted)

UPDATE (more verbose…as requested)

age = int(input('What is your age?: '))
accepted = age >= 18
print('yes' if accepted else 'no')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading