【发布时间】:2018-04-05 12:18:24
【问题描述】:
我正在编写一个掷两个骰子的程序;然后根据滚动的内容分配积分;并保留运行总计。到目前为止,我有这个;但我一直遇到“int is not callable”的错误。有人可以帮忙吗?
import random
def dice():
a = 1
b = 6
return random.randint(a,b)
rollOne = int(dice())
rollTwo = int(dice())
def greeting():
option = input('Enter Y if you would like to roll the dice: ')
if option == 'Y':
print('You have rolled a' , rollOne, 'and a' , rollTwo)
points = []
if rollOne() == rollTwo():
points.append(10)
print('You have a total of %d points' % (sum(points)))
if rollOne == 6 or rollTwo ==6:
points.append(4)
print('You have a total of %d points' % (sum(points)))
if (rollOne + rollTwo) == 7:
points.append(2)
print('You have a total of %d points' % (sum(points)))
dice()
greeting()
【问题讨论】:
-
去掉
if rollOne() == rollTwo():的括号 -
请注意,对于一对六,您将获得 10 分(因为相同),然后是 4 分,因为两者都是六。不确定这是否是故意的......
标签: python python-3.x random dice cumulative-sum