0

Add a conditional statement in existing code to check if they qualified to be president!

I hope someone can explain to me step by step how to add a conditional if and else, so that the output will display: If age >= 35: print("congratulations you're qualified to be a president!") Else: Print ("Please try again next year! Thanks") The output will be - > Check your age qualified Your age is _ Congratulations you're qualified to be a president! OR Please try again next year! Thanks Here my code: https://code.sololearn.com/cy700ENcwc3V/?ref=app Thanks

2nd Apr 2018, 6:54 PM
Amin Shahril
Amin Shahril - avatar
3 Respuestas
+ 1
If you need to use functions I'd leave it to the first two and ditch the display funcion entirely. just call the second function from the first one and in the second one just do the age check if enter plaplapla: display stuff This is how i'd solve it if that would need to be the structure, just need change it a bit since i fast wrote it :D # I want user to insert age def age_to_be_president(): enter = input('Check if your age qualified.\n ') enter = int(enter) return enter def let_say_age(enter): print('Your age is {}.'.format(enter)) def displayAgeResult(): enter = age_to_be_president() let_say_age(enter) if enter > 20: print("aa") else: print("bb") displayAgeResult()
2nd Apr 2018, 9:14 PM
Markus Kaleton
Markus Kaleton - avatar
+ 3
I think your code isn’t that bad but I don’t think there’s a need for the functions I would do something like: usrAge = int(input("Give me your age: ")) if usrAge >= 35: print("\nYou are old enough to be the president.") else: print("\nYou are not old enough to be the president, try again next year.")
2nd Apr 2018, 7:06 PM
TurtleShell
TurtleShell - avatar
+ 1
Wow so simple both solutions. Why I don't even think about it. 😂😅
3rd Apr 2018, 2:25 AM
Amin Shahril
Amin Shahril - avatar