My python code if statements not working. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

My python code if statements not working.

My if statements arent working. Even when i enter "No", it still acts as though i typed Yes. :( print ('Welcome to the game of life!') print ('Enter date of birth!') input('You are born on :') print ('You are now going to school.') print ('Do you get good grades or choose to learn programming instead?\ "Yes" for good grades or "No" for programming.') Yes = True No = False input() if No: print ("You get very bad grades in school from not studying. \ You're parents are angry with you. \ However, you love programming so much you start putting\ apps on the store and making small games for fun.\ It brings in some extra money.") else : print('You do great in school and your parents are proud of you!')

22nd Jun 2017, 5:20 AM
Iris Eye
Iris Eye - avatar
3 Answers
+ 2
Let's see how your code works. First you assign two variables: Yes=True No=False So the variable "No" has the value False. Then, you do: if No: ... Since No=False, you are simply doing an "if False". Which means that the code under that if never executes). You need to capture the result of the input() (right now, you are just throwing it away), and compare that result to "yes" or "no". good_grades = input() if good_grades=='No': print (...)
22nd Jun 2017, 5:33 AM
Bogdan Sass
Bogdan Sass - avatar
+ 1
In your code Yes and No are new variables that you define and have nothing to do with the "Yes" and "No" that you input. Those are values, not variables.
22nd Jun 2017, 6:50 AM
Adrian
Adrian - avatar
0
I tried rotating it but it still didn't work ;-; print ('You are now going to school.') print ('Do you get good grades or choose to learn programming instead?\ "Yes" for good grades or "No" for programming.') Yes = True No = False input() if True: print('You do great in school and your parents are proud of you!') else: print ("You get very bad grades in school from not studying. \ You're parents are angry with you. \ However, you love programming so much you start putting\ apps on the store and making small games for fun.\ It brings in some extra money.")
22nd Jun 2017, 5:49 AM
Iris Eye
Iris Eye - avatar