Python Forum

Full Version: build a list (add_animals) using a while loop, stop adding when an empty string is en
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
my question here
build a list (add_animals) using a while loop, stop adding when an empty string is entered
add_animals =[]
user_input=input("Enter animals names:")
while user_input!=" ":
    add_animals.append(user_input)
print(add_animals)
but I am not getting the proper output.
You should get the user input in the loop.
Also, empty string is "", not " ". The latest being space, not empty string

add_animals =[]
while True:
    user_input=input("Enter animals names:")
    if user_input:
        add_animals.append(user_input)
    else:
        break
print(add_animals)