在python 3中保持总得分

时间:2017-10-24 15:53:23

标签: python python-3.x random dice running-total

我正在写一个滚动两个骰子的程序;然后根据滚动的内容,分配点数;并保留一个总计。到目前为止,我有这个;但我一直遇到“int不可调用”的错误。有人可以帮忙吗?

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()

2 个答案:

答案 0 :(得分:2)

dice()的结果是一个名为rollOnerollTwo的整数。

他们不能被称为"就像你试图做rollOne()

要解决错误,请从行中删除括号(您在其他if语句中已执行此操作)

if rollOne() == rollTwo(): 

变为

if rollOne == rollTwo: 

答案 1 :(得分:0)

问题在于此,

   if rollOne() == rollTwo():

rollone和rolltwo是返回值而不是函数