Попытка создать функцию (python), которая просматривает список строк, принимает входные данные, а затем на основе входныPython

Программы на Python
Ответить
Anonymous
 Попытка создать функцию (python), которая просматривает список строк, принимает входные данные, а затем на основе входны

Сообщение Anonymous »

Я не уверен, почему «quit» не завершает функцию, и я получаю сообщение об ошибке, когда вводится пробел/ничего, хотя в списке осталась еще одна строка.
(Я должен уточнить, что я всего лишь студент и у меня очень строгие требования к тому, какие вещи/методы использовать)
Вот мой код на данный момент..
animal_list = ["cat", "wolf", "horse"]

def listomatic():
#animal = input("Enter the name of an animal or 'quit' to quit: ")
while animal_list != []:
#list = ["cat", "wolf", "horse"]
animal = input("Enter the name of an animal or 'quit' to quit: ")
if animal == "":
print("Welcome name. Look at this list of animals : ", animal_list, "\n")
animal_list.pop()
popped_animal = animal_list.pop()
print_this3 = print("Enter the name of an animal: ", animal, "\n",
popped_animal, "was popped from list")
#return print_this3
elif animal == "quit":
print_this4 = print("Welcome name. Look at this list of animals : ", list, "\n",
"Enter the name of an animal: ", animal, "\n",
"Goodbye!")
return
elif animal in animal_list:
print("Welcome name. Look at this list of animals: ", animal_list)
animal_list.remove(animal)
print_this1 = print(#"Welcome name. Look at this list of animals: ", animal_list, "\n",
"Enter the name of an animal: ", animal, "\n",
"1 instance of " + animal + " removed from list")
#return print_this1
elif animal not in animal_list:
print("Welcome name. Look at this list of animals: ", animal_list, "\n")
animal_list.append(animal)
print_this2 = print(#"Welcome name. Look at this list of animals: ", animal_list, "\n",
"Enter the name of an animal: ", animal, "\n",
"1 instance of " + animal + " appended to list")
#return print_this2

#break
else:
print("Goodbye!")

break

listomatic()
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»