Question
What needs to be changed about this code for it to run properly? validChoice = True while not validChoice: animal = input(Enter an animal you
What needs to be changed about this code for it to run properly?
validChoice = True while not validChoice: animal = input("Enter an animal you want for a pet: ") locale = input("Enter continent where you want to live: ") if animal == "giraffe" and locale == "Africa": validChoice = False elif (animal == "dog" or animal == "cat") and locale != "Antarctica": validChoice = False elif animal == "rabbit" and locale != "Australia": validChoice = False else: print("Sorry, that's not a good place for that animal to live.")
Start with validChoice equal to False, and set it to True inside the if/elif statements | ||
Start with validChoice equal to False, and set it to True as soon as we enter the while loop | ||
Change the elif statements to if statements, and remove the else | ||
Don't set validChoice until we're inside the loop |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started