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.

>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')

Leave a Reply