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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!