Мне нужна помощь в этом, я новичок в python. мое назначение - создать программу, в которой пользователь выбирает категорию, а затем скремблировать слова из файла, находящегося в этой категории. Я просто хочу понять, почему эта первая часть не работает, первая часть является первым из четырех разных методов, которые выполняются в зависимости от того, какую категорию выбирает пользователь.выбор файла и чтение его слов python
print ("Instructions: Enter your chosen category, animals, places, names or colors.")
viewYourFile = input("Enter your category")
category = 'animals'
if category == 'animals':
animals = open('animals.txt')
next = animals.read(1)
while next != "":
animal1 = animals.read(1)
animal2 = animals.read(2)
animal3 = animals.read(3)
animal4 = animals.read(4)
animal5 = animals.read(5)
animalList = ['animal1', 'animal2', 'animal3', 'animal4', 'animal5']
chosenAnimal = random.choice(animalList)
animalLetters = list(chosenAnimal)
random.shuffle(animalLetters)
scrambledAnimal = ' '.join(animalLetters)
print(scrambledAnimal)
print("Enter the correct spelling of the word")
Ваш отступы повсюду; пожалуйста, исправьте. –
Это лучше? – Naxty
Не совсем. Этот код все равно не будет работать. – Prune