Reputation:
I just got into coding. One of my projects was to create a smalltalk interview with myself. Everything went well until this :
if (sport == answer or sport == answer3 or sport == answer5): #Yes
if (vidgames == answer or vidgames == answer3 or vidgames == answer5): #Yes
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", your favorite sport(s) are/is " + favsport + ", and your favorite video game(s) are/is " + favgame + ". Very interesting!")
print()
elif (sport == answer2 or sport == answer4 or sport == answer6): #No
if (vidgames == answer2 or vidgames == answer4 or vidgames == answer6): #No
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", and you don't play any sports or video games. Very interesting!")
print()
elif (sport == answer or sport == answer3 or sport == answer5): #Yes
if (vidgames == answer2 or vidgames == answer4 or vidgames == answer6): #No
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", your favorite sport(s) are/is " + favsport + ", but you don't play any video games. Very interesting!")
print()
elif (sport == answer2 or sport == answer4 or sport == answer6): #No
if (vidgames == answer or vidgames == answer3 or vidgames == answer5): #Yes
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", your favorite video game(s) are/is " + favgame + ", but you don't play any sports. Very interesting!")
print()
farewell = input("Well, " + name + ", I must leave now. It was nice meeting you! I hope we meet again.")
If I respond with yes and then no (or vice-versa), the print message will not show up. If I respond with the same answers for both of them, the message WILL show up. The only thing that shows up all the time is the "farewell" variable. Thank you for helping me.
Upvotes: 0
Views: 176
Reputation: 20346
In the case of yes and then no: It first checks to see if the first is yes. It finds that it is. It then checks to see if the second is yes. It is not; it proceeds to the next elif
. Since elif
means else if
, it finds that it already came across a true statement, (the first is yes). This is why it doesn't work. Here is a cleaned-up version of your code:
if sport in (answer, answer3, answer5): #Yes
if vidgames in (answer, answer3, answer5): #Yes
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", your favorite sport(s) are/is " + favsport + ", and your favorite video game(s) are/is " + favgame + ". Very interesting!")
print()
elif vidgames in (answer2, answer4, answer6): #No
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", your favorite sport(s) are/is " + favsport + ", but you don't play any video games. Very interesting!")
print()
elif sport in (answer2, answer4, answer6): #No
if vidgames in (answer2, answer4, answer6): #No
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", and you don't play any sports or video games. Very interesting!")
print()
elif vidgames in (answer, answer3, answer5): #Yes
print("So, " + name + ", from what i've learned, you like to eat " + favfood + ", your favorite color is " + color + ", your favorite video game(s) are/is " + favgame + ", but you don't play any sports. Very interesting!")
print()
farewell = input("Well, " + name + ", I must leave now. It was nice meeting you! I hope we meet again.")
Upvotes: 1