Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 需要关于猪骰子游戏的帮助或建议吗_Python - Fatal编程技术网

Python 需要关于猪骰子游戏的帮助或建议吗

Python 需要关于猪骰子游戏的帮助或建议吗,python,Python,我以前没有编程经验,这学期我要上我的第一节编程课,我需要一些关于我做错了什么的帮助,或者关于从这里走到哪里的建议。我仍然需要添加计算机对手,但我遇到的一个问题是暂停部分有时才起作用。当它要求再次滚动或保持时,我按H键保持,有时它工作,而其他时候,它的动作就像我再次滚动时按R键一样。任何帮助都将不胜感激 这就是我到目前为止所做的: import random p1 = 0 p2 = 0 print ("Score" "\tYou :", p1, "\tAI :", p2) still_pla

我以前没有编程经验,这学期我要上我的第一节编程课,我需要一些关于我做错了什么的帮助,或者关于从这里走到哪里的建议。我仍然需要添加计算机对手,但我遇到的一个问题是暂停部分有时才起作用。当它要求再次滚动或保持时,我按H键保持,有时它工作,而其他时候,它的动作就像我再次滚动时按R键一样。任何帮助都将不胜感激

这就是我到目前为止所做的:

import random

p1 = 0
p2 = 0

print ("Score" "\tYou :", p1, "\tAI :", p2)

still_playing = True
hold_pass_input = False

while still_playing:

    while True:

        p1_turn = input ("Your turn. Hit enter to continue.")
        p1_score = p1
        p2_score = p2
        break

    while (p1_score >= 0 and p1_score <= 50):
        die_roll = random.randint (1,6)

        if die_roll > 1:
            p1_score = die_roll + p1_score
            print("Die :", die_roll, "Pot :", p1_score,)

            hold_pass = input("(R)oll again or (H)old?:").upper()
            while hold_pass_input == False:

                if hold_pass in ["r", "R"]==["r", "R"]:
                    hold_pass_input = True
                    break

                elif hold_pass in["h","H"]==["h","H"]:
                    hold_pass_input = False
                    print ("Score" "\tYou :", p1_score, "\tAI :", p2_score)
                    print("It's the computers turn. Hit enter to continue.")
                    break

                else:
                    hold_pass_input = False
                    print("Use only R, r, H, h")
                    hold_pass = input("(R)oll again or (H)old?:").upper()

        elif die_roll <= 1:
            p1_score = p1_score - p1_score
            print("Die :", die_roll, "Pot :", p1_score, "Bust")
            p2_turn = input("It's the computers turn. Hit enter to continue.")
随机导入
p1=0
p2=0
打印(“分数”\tYou:,p1,\tAI:,p2)
还在玩吗
保持\通过\输入=错误
当你还在玩的时候:
尽管如此:
p1\u回合=输入(“你的回合。点击回车键继续。”)
p1_分数=p1
p2_分数=p2
打破
而(p1_分数>=0和p1_分数1:
p1_分数=骰子掷骰+p1_分数
打印(“模具:,模具辊,罐:,p1_分数,)
hold_pass=input(“(R)oll再次或(H)old?:”)
保持时,输入=False:
如果在[“r”,“r”]=“r”,“r”]中保持通过:
保持\通过\输入=真
打破
elif hold_pass in[“h”,“h”]=“h”,“h”]:
保持\通过\输入=错误
打印(“分数”\tYou:,p1\U分数,\tAI:,p2\U分数)
打印(“轮到计算机了,按回车键继续。”)
打破
其他:
保持\通过\输入=错误
打印(“仅使用R、R、H、H”)
hold_pass=input(“(R)oll再次或(H)old?:”)

elif die_roll如果elif else
-块,我认为问题在于您的

您可以这样做:

if hold_pass in ["r", "R"]==["r", "R"]:
中关键字
后的位最有可能计算为
True
,因此从某种意义上讲,该行与:

if hold_pass in True:
这没什么意义

尝试这样做:

if hold_pass in ["r", "R"]:
该错误也存在于
elif
-子句中:

elif hold_pass in["h","H"]==["h","H"]:
应该是:

elif hold_pass in ["h","H"]: