[英]Need help or any advice on a PIG dice game
我以前没有编程方面的经验,本学期我将参加第一门编程课程,需要我做错什么的帮助或关于从此处走的建议。我仍然需要补充计算机对手,但我有一个问题拥有部分只是有时起作用。 当它要求再次滚动或按住时,我按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.")
我认为问题出在您的if-elif-else
-block内。
你做这个:
if hold_pass in ["r", "R"]==["r", "R"]:
关键字in
之后的位很可能会评估为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"]:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.