If you have any questions, comments or issues with this project please post them here!
I dont know how to add the while loop in this code. I added it at the beginning but it kept repeating endlessly and I don’t know how to define the end of the loop. I wrote the code below.
The request is “Write a program that loops. Inside the loop, ask the user what animal sound they want to hear”
What animal do you want?: Cow
A cow goes moo.
Do you want to exit?: no
What animal do you want?: A Lesser Spotted lemur
Ummm…the Lesser Spotter Lemur goes awooga.
Do you want to exit?: yes
animal = input("What animal sounds do you want to hear? ")
if animal == “cow”:
print(“A cow goes moo”)
elif animal == “lemur”:
print(“Ummm…the lemur goes awooga”)
print(“Try cow or lemur”)
exit = input(“do you want to exit?”)
while True: animal = input("What animal sounds do you want to hear? ") if animal == "cow": print("A cow goes moo") elif animal == "lemur": print("Ummm…the lemur goes awooga") else: print("Try cow or lemur") exit = input("do you want to exit?") if exit == "yes": break else: continue
break will exit the while loop and
continue will continue the loop
break keyword to
break from the while loop.
if exit == "exit": break
Thank you so much for the quick reply!
Just moved your post and replies to Day 015 topic so others can find it if needed!
What does the say ? Find out with my custom animal sound generator (just like Alexa)!
Day 15 of #Replit100DaysOfCode #100DaysOfCode.