第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

if, elif & !=, == 布爾運算僅在輸入時返回“false”

if, elif & !=, == 布爾運算僅在輸入時返回“false”

慕容708150 2023-12-29 15:04:37
我正在創(chuàng)建一個“我們之中”的盜版(為了好玩?。?,而 while True 和 if/elif/else 語句只會返回 false(不是冒名頂替者)的輸入。我創(chuàng)建了一個姓名列表,列表中的 2 個隨機元素將被選為An Impostor。但是,每當我輸入The Impostor的名稱時,它只會返回(玩家)不是冒名頂替者。這是我的代碼;import sys, time, randomnames = ["player1", "player2", "player3", "player4", "player5", "player6", "player7", "player8", "player9", "player10"]print("Players: ")for x in names:  print(x)print('—————————————————————————')impostor1 = random.choice(names)impostor2 = random.choice(names)crewmates = 8impostors = 2tries = 6while True:  talk = input("Guess who The Impostor(s) are. " + str(crewmates) + " Crewmates are left. " + str(impostors) + " Impostors are left. You have " + str(tries) + " tries left.")  if talk in names:    print(talk + " was voted for.")    time.sleep(0.1)    if talk != impostor1 or talk != impostor2:      notimp = talk + " was not An Impostor. "      names.remove(talk)      for y in notimp:        sys.stdout.write(y)        sys.stdout.flush()        time.sleep(0.05)      crewmates -= 1      tries -= 1    elif talk == impostor1 or talk == impostor2:      wasimp = talk + " was An Impostor. "      names.remove(talk)      for v in wasimp:        sys.stdout.write(v)        sys.stdout.flush()        time.sleep(0.1)      impostors -= 1  else:    print("That player was either ejected or is not a valid player.")但是,每當我將冒名頂替者放入輸入中時,它都會說它不是冒名頂替者?
查看完整描述

1 回答

?
慕容森

TA貢獻1853條經(jīng)驗 獲得超18個贊

我認為這一行是問題的根源:

if talk != impostor1 or talk != impostor2:

假設(shè)impostor1isplayer1 和impostor2isplayer2 以及inputplayer1中的某個人,根據(jù)PythonBoolean表達式運算符,orif語句的計算結(jié)果如下:

if player1 != impostor1評估為False因為player1 確實等于impostor1。

到目前為止一切順利,但由于第一個測試是False,Python 只是計算并返回右側(cè)操作數(shù),該操作數(shù)可能是TrueFalse。在你的情況下,Python 將評估if talk != impostor2并返回True,然后執(zhí)行嵌套塊。


查看完整回答
反對 回復(fù) 2023-12-29
  • 1 回答
  • 0 關(guān)注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號