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

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

搖滾,紙,剪刀 Python

搖滾,紙,剪刀 Python

紫衣仙女 2022-10-06 16:12:28
我正在嘗試構(gòu)建一個石頭、紙、剪刀游戲。我似乎無法讓代碼進行鍛煉,因為無論我做出什么選擇,贏家總是電腦!我的電腦有偏見嗎?感謝您的幫助 !import randomcomp_list = ['Rock', 'Paper', 'Scissors']computer = c  = 0command = p = 0print("Scores: Computer " + str(c) + " player " + str(p))while True:    comp = random.choice(comp_list)    command = input("rock , paper, scissors or quit :").lower()    if command == comp :        print("break even")    elif command == "rock":        if comp == "scissors":            print("player won")            p += 1        else:            print("computer won")            c +=1    elif command == "paper":        if comp == "rock":            print("player won")            p += 1        else :            print("computer won")            c += 1    elif command == "scissors":        if comp == "paper":            print("player won")            p += 1        else :            print("computer won")            c += 1    elif command == "quit":        break    else :        print("wrong command! ")    print("Player: " + command)    print("computer: " + comp)    print("")    print("Scores: Computer " + str(c) + " player " + str(p))    print("")
查看完整描述

1 回答

?
蝴蝶刀刀

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

您的計算機總是生成一個大寫字符串 ex

Rock

你的輸入總是小寫的

rock

在 python 字符串情況下很重要,所以當你比較時

if command == comp:

這是比較

"Rock" == "rock" # -> which is false

您可以通過對字符串使用全部小寫來修復(fù)您的代碼。只需將頂部的數(shù)組更改為全部小寫即可

['rock', 'paper', 'scissors']


查看完整回答
反對 回復(fù) 2022-10-06
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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