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!')
3 Antworten
+ 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 (...)
+ 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.
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.")