Я не уверен, почему «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()
Попытка создать функцию (python), которая просматривает список строк, принимает входные данные, а затем на основе входны ⇐ Python
Программы на Python
1774471543
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()
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия