[英]Why my IF statement and OR operator doesn't give me the expected output?
我實際上不確定這里出了什么問題,但是代碼沒有給我我想要的。
從技術上講,我想要它做的是,如果我寫下字典中的“0”(可能更多,取決於它有多少項目)或“N”,它將停止。 但它不起作用。 它總是運行 if 而不是 else。
是我看不到明顯的東西還是只是一個錯誤(不太可能)
from time import sleep
inventory = {}
character = {'Energy': 180}
inventory['Red Mushroom'] = {'Quantity': 1,
'Description': 'It looks good for the Energy, but also a tasteful snack...',
'Effect': 35}
def show_inve():
sleep(1)
mapear = {}
if inventory == {}:
print('Its empty...\n')
else:
for i, pos in enumerate(inventory):
print(f'[{i}] {pos:<10}: {inventory[pos]["Quantity"]:>0}')
mapear[str(i)] = pos
while True:
sleep(1)
decision = input('Type the number of the item or N to leave: ').strip()
if decision not in mapear or decision != 'N':
sleep(1)
print('Not an option.')
continue
else:
break
show_inve()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.