Почему мои вложенные циклы while не работают должным образом? [дубликат]Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Почему мои вложенные циклы while не работают должным образом? [дубликат]

Сообщение Anonymous »

Я пишу текстовую игру для колледжа. Я увлекся и сделал все возможное. Я думал, что уже собираюсь закончить, когда понял, что часть кода take_item не работает, потому что я использовал все операторы IF, поэтому я изменил, если пользовательский ввод не равен «да» или «нет» в цикле while. который печатает сообщение о недопустимом вводе, а затем снова предлагает пользователю ввести данные.
Проблема в том, что независимо от того, что я набираю сейчас, включая «да» и «нет», он печатает недопустимое сообщение и просто остается в цикле.
Я исключил свой словарь и другие вещи и включил свой код только из начального игрового цикла почти до его конца. Я выделил вложенные циклы while с заглавной буквы, чтобы их было легче найти.
while user_command != 'Exit':
#if statement for valid commands
if user_command in move_direct:
user_command = user_command.replace('Go ', '')
if user_command in rooms[current_room]:
os.system('cls')
current_room = rooms[current_room][user_command]
if boss_room == current_room:
os.system('cls')
print('you encountered the kracken without all items, you lose')
exit()
print('You have entered the {}.'.format(current_room))

if 'item' in rooms[current_room]['other']:
rooms[current_room]['other']['count'] += 1
if rooms[current_room]['other']['count'] == 1:
print()
print('{}\n'.format(rooms[current_room]['other']['descript1']))
if len(inventory) == 0:
print("Your inventory: [empty]\n")
else:
print('Your inventory:', ', '.join(inventory))
print()

take_item = input('Would you like to retrieve the item? Type: yes or no\n').lower()
WHILE take_item != 'yes' or 'no':
print('You have entered an invalid command')
take_item = input('Would you like to retrieve the item? Type: yes or no\n').lower()
if take_item == 'yes':
os.system('cls')
inventory.append(rooms[current_room]['other']['item'])
if len(inventory) >= 7:
print(win_game)
exit()
del rooms[current_room]['other']['item']
print('Your inventory:', ', '.join(inventory))
print('your location: {}\n'.format(current_room))
user_command = input('Please enter a direction or type "exit" to exit the game:\n').title()
else:
os.system('cls')
if len(inventory) == 0:
print('Your inventory: [empty]')
else:
print('Your inventory:', ', '.join(inventory))
print('your location: {}\n'.format(current_room))
user_command = input('Please enter a direction or type "exit" to exit the game:\n').title()
else:
print()
print('{}\n'.format(rooms[current_room]['other']['descript2']))
if len(inventory) == 0:
print('Your inventory: [empty]\n')
else:
print('Your inventory:', ', '.join(inventory))
take_item = input('Would you like to retrieve the item? Type: yes or no\n').lower()
WHILE take_item != 'yes' or 'no':
print('You have entered an invalid command')
take_item = input('Would you like to retrieve the item? Type: yes or no\n').lower()
if take_item == 'yes':
os.system('cls')
inventory.append(rooms[current_room]['other']['item'])
if len(inventory) >= 7:
print(win_game)
exit()
del rooms[current_room]['other']['item']
print('Your inventory:', ', '.join(inventory))
print('your location: {}\n'.format(current_room))
user_command = input('Please enter a direction or type "exit" to exit the game:\n').title()
else:
os.system('cls')
if len(inventory) == 0:
print('Your inventory: [empty]')
else:
print('Your inventory:', ', '.join(inventory))
print('your location: {}\n'.format(current_room))
user_command = input('Please enter a direction or type "exit" to exit the game:\n').title() ```


Подробнее здесь: https://stackoverflow.com/questions/786 ... s-intended
Реклама
Ответить Пред. темаСлед. тема

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

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

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

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

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Как я могу завершить вложенные циклы while, если доска заполнена?
    Anonymous » » в форуме Python
    0 Ответы
    10 Просмотры
    Последнее сообщение Anonymous
  • Как я могу завершить вложенные циклы while, если доска заполнена?
    Anonymous » » в форуме Python
    0 Ответы
    9 Просмотры
    Последнее сообщение Anonymous
  • Почему мой цикл while не выполняется должным образом? [дубликат]
    Anonymous » » в форуме Python
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Чтобы напечатать шаблон в Python, используя вложенные циклы for
    Гость » » в форуме Python
    0 Ответы
    26 Просмотры
    Последнее сообщение Гость
  • Как оптимизировать вложенные циклы для тензорных операций в NumPy/TensorFlow?
    Гость » » в форуме Python
    0 Ответы
    26 Просмотры
    Последнее сообщение Гость

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