【发布时间】:2019-06-28 03:35:17
【问题描述】:
我正在做一个骰子游戏,当玩家角色为偶数时,分数增加 10。但是如果数字是奇数,则分数减少 5。如果用户角色加倍,则允许额外滚动骰子 - 其他陈述适用于 3 个骰子的总分。我的 if 语句没有运行。我试图将列表中的数字更改为字符串,但它不起作用。
def Player_1_Roll():
global Player_1_Score
Player_1_Score = 0
Player_1_Roll_1 = random.randint(1, 6)
print(Player_1_Name, "'s first roll is", Player_1_Roll_1)
time.sleep(1)
Player_1_Roll_2 = random.randint(1, 6)
print(Player_1_Name, "'s second roll is", Player_1_Roll_2)
Player_1_Score = Player_1_Roll_1 + Player_1_Roll_2
if Player_1_Score == [2, 4, 6, 8, 10, 12, 14, 16, 18]:
Player_1_Score = Player_1_Score + 10
print(Player_1_Name, "'s Score is", Player_1_Score)
elif Player_1_Score == [1, 3, 5, 7, 9, 11, 13, 15, 17]:
Player_1_Score = Player_1_Score - 5
print(Player_1_Name, "'s Score is", Player_1_Score)
elif Player_1_Score < 0:
Player_1_Score = 0
print(Player_1_Name, "'s Score is", Player_1_Score)
elif Player_1_Roll_1 == Player_1_Roll_2:
print("")
print(Player_1_Name, "rolled doubles!")
print("")
Player_1_Roll_3 = random.randint(1, 6)
print(Player_1_Name, "'s bonus roll is", Player_1_Roll_3)
Player_1_Score = Player_1_Score + Player_1_Roll_3 + Player_1_Roll_1 + Player_1_Roll_2
print(Player_1_Name, "'s Score is", Player_1_Score)
【问题讨论】:
-
请修正缩进;目前还不清楚什么是函数的一部分,什么不是。
-
所有代码都在函数中
-
@KianL 然后edit你的问题来证明这一点。
-
问题出在
if Player_1_Score == [2 , 4 , 6 , 8 , 10 , 12 , 14 , 16 , 18]:。玩家的分数是一个整数,您将它与一个列表进行比较,您只想检查它是否是该集合的一部分。
标签: python python-3.x