擅长:python、mysql、java
<pre><code>num_animals = 0
tot_animals = 4
all_names = ""
while num_animals <= tot_animals:
# Doing this within the while loop will prompt the user for input
# each iteration of the loop.
animal_name = input("Put in 4 animal names in total per time or \"exit\" for break")
if animal_name.lower() == "exit":
break
num_animals += 1
# This will append the user's input to all_names
all_names += animal_name + " "
if len(all_names) == 0:
print("no animals")
else:
print("names of all animals: ", all_names)
</code></pre>