Hello Forum!
I am new here and also at Python. I am currently learning Python through archived material on edx (a Microsoft Learning Platform). My current challenge is a task involving Nested Conditionals. Essentially it is code using nested if statements in a guessing application. I am trying to use user prompts to let users make a maximum of 3 guesses from a variable containing bird names.
The first part of the code (the part with nested if statements) never runs. Only the else part seems to execute. Kindly tell me what I am doing wrong. Find the task and code below.
Thank you.
Task
Nested if - testing for False
Program: [ ] 3 Guesses
use nested if statements complete the flowchart code
create a birds string variable with the names of 1, 2, 3 or more birds to make it easier
get bird_guess input and use bird_guess in bird_names to generate Boolean True/False
if the the guess is wrong (False) create a sub test until the user has had 3 guesses
My Code
# [ ] Create the "Guess the bird" program
print("Welcome to the Bird Guess Game!")
birds = ("Pigeon, Eagle, Parrot, Chicken, Turkey, Macaw, Duck, Geese")
# print(birds)
print()
bird_guess = input("Name a bird you think is on the bird list: ")
if bird_guess.title() in birds == False:
print("Wrong! You have 2 more guesses.")
next_guess = input("Name a bird you think is on the bird list: ")
if next_guess.title() in birds == False:
print("Wrong! You have 1 more guess.")
last_guess = input("Name a bird you think is on the bird list: ")
if last_guess.title() in birds == False:
print("Wrong! Sorry you are out of guesses.")
else:
print("Correct! You got it on your 3rd and last try.")
else:
print("Correct! You got it on your 2nd try.")
else:
print("Correct! You got it on your 1st try.")
I am new here and also at Python. I am currently learning Python through archived material on edx (a Microsoft Learning Platform). My current challenge is a task involving Nested Conditionals. Essentially it is code using nested if statements in a guessing application. I am trying to use user prompts to let users make a maximum of 3 guesses from a variable containing bird names.
The first part of the code (the part with nested if statements) never runs. Only the else part seems to execute. Kindly tell me what I am doing wrong. Find the task and code below.
Thank you.
Task
Nested if - testing for False
Program: [ ] 3 Guesses
use nested if statements complete the flowchart code
create a birds string variable with the names of 1, 2, 3 or more birds to make it easier
get bird_guess input and use bird_guess in bird_names to generate Boolean True/False
if the the guess is wrong (False) create a sub test until the user has had 3 guesses
My Code
# [ ] Create the "Guess the bird" program
print("Welcome to the Bird Guess Game!")
birds = ("Pigeon, Eagle, Parrot, Chicken, Turkey, Macaw, Duck, Geese")
# print(birds)
print()
bird_guess = input("Name a bird you think is on the bird list: ")
if bird_guess.title() in birds == False:
print("Wrong! You have 2 more guesses.")
next_guess = input("Name a bird you think is on the bird list: ")
if next_guess.title() in birds == False:
print("Wrong! You have 1 more guess.")
last_guess = input("Name a bird you think is on the bird list: ")
if last_guess.title() in birds == False:
print("Wrong! Sorry you are out of guesses.")
else:
print("Correct! You got it on your 3rd and last try.")
else:
print("Correct! You got it on your 2nd try.")
else:
print("Correct! You got it on your 1st try.")