【发布时间】:2019-03-20 09:51:14
【问题描述】:
如何进行以下工作(在 Python 中)?
import random
def roll():
input1 = input("Player1, type 'ROLL' to roll.")
if (input1 == "ROLL"):
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
print("You rolled a " + dice1() + " and a " + dice2() ".")
else:
pass
roll()
我明白了:
File "main.py", line 9
print("You rolled a " + dice1() + " and a " + dice2() ".")
^
SyntaxError: invalid syntax
我还希望它重复“Player1,输入'ROLL'来滚动”。如果输入不等于 ROLL。
【问题讨论】:
-
您在打印行忘记了逗号
-
上面的代码有什么问题?
-
你试过什么?你想做什么...请在问题中说明
-
为什么要在 dice1 和 dice2 上加上括号?他们每个人都被分配了一些整数。只需使用 str(dice1) 和 str(dice2),或带有 %d 的格式字符串。
标签: python