Search code examples
pythonpython-3.xrandomdicecumulative-sum

Keeping a running total of score in python 3


I am writing a program that rolls two dice; and then according to what is rolled, points are assigned; and a running total is kept. So far, I have this; but I keep running into an error of "int is not callable". Can someone please help?

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

Solution

  • The result from dice() is an integer which you have named rollOne and rollTwo.

    They cannot be "called" like you have tried to do rollOne().

    In order to solve the error, remove the brackets from the line (which you have done in your other if statements)

    if rollOne() == rollTwo(): 
    

    becomes

    if rollOne == rollTwo: