Я работаю над текстовой игрой. Мой код работает нормально, но оператор else в самом конце кода печатает, даже если мой оператор if правда. Как я могу это исправить?
else:
print ("недействительный ввод")
выполняется независимо от того, какой ввод
Id, как он показывает только тогда, когда операторы Win /проигрывают false < /p>
def show_instructions():
print('---------------------------'),
print("Welcome to the Zombie Apocalypse Text Game"),
print("Collect all 6 items, or lose to a zombie hoard"),
print("Your move commands are: 'North, East, South, West'"),
print("Add an item to your inventory: Get 'Item Name'"),
print('---------------------------')
def player_status():
print(inventory)
def main():
player_status()
rooms={
'Reception':{'East':'Interview Room', 'South':'Intake'}, #starting room
'Interview Room':{'West':'Reception', 'item':'ammo'},
'Intake':{'West':'Holding Cell','South':'General Population','East':'Equipment Room',
'North':'Reception','item':'flash bang'},
'Holding Cell':{'East':'Intake', 'item':'handgun'},
'General Population':{'North':'Intake', 'East':'Yard', 'item':'shank'},
'Equipment Room':{'West':'Intake', 'North':'Wardens Office','item':'riot gear'},
'Wardens Office':{'South':'Equipment Room', 'item':'shotgun'},
'Yard':{'West':'General Population', 'villain':'zombies'}} #Zombies
starting_room = 'Reception'
current_room = starting_room
directions = 'north', 'east', 'south', 'west'
items =[{'Reception':'None'}]
inventory = []
while True:
show_instructions()
if 'item' in rooms[current_room]:
items = rooms[current_room]['item']
print('you see {}'.format(items))
print('\nYou are currently in {}'.format(current_room))
print(inventory)
# players input, IE: directions or picking up items
user_input = input(f'Enter your move command: ').capitalize().split()
if user_input[-1] == 'Exit':
print("Thank you for playing")
break
elif user_input[-1] in rooms[current_room]:
user_input = user_input[-1]
current_room =rooms[current_room][user_input]
# players get item input
elif user_input[0] == 'Get':
item = ' '.join(user_input[1:])
if 'item' in rooms[current_room] and item == rooms[current_room]['item']:
inventory.append(item)
else:
print('Invalid command')
# lose condition
if current_room == 'Yard' and len(inventory) < 6:
print("You weren't able to collect all the items")
print("You weren't able to clear the yard")
# win condition
elif current_room == 'Yard' and len(inventory) > 6:
print("CONGRATS!! You were able to collect all items and")
print("You were able to clear the yard")
# if an input other than get or direction is input
else:
print("Invalid input")
Подробнее здесь: https://stackoverflow.com/questions/795 ... -same-time
Мой код запускает как мой оператор IF, так и My Else оператор одновременно? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Мой код запускает как мой оператор IF, так и My Else оператор одновременно?
Anonymous » » в форуме Python - 0 Ответы
- 11 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Мой код запускает как мой оператор IF, так и My Else оператор одновременно?
Anonymous » » в форуме Python - 0 Ответы
- 7 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Назначение в (else), если оператор запускает предупреждение в MSVC, но не в GCC / Clang
Anonymous » » в форуме C++ - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Назначение в (else), если оператор запускает предупреждение в MSVC, но не в GCC / Clang
Anonymous » » в форуме C++ - 0 Ответы
- 3 Просмотры
-
Последнее сообщение Anonymous
-