保持 运行 总分 python 3
Keeping a running total of score in python 3
我正在编写一个掷两个骰子的程序;然后根据掷出的东西分配分数;并保留 运行 总数。到目前为止,我有这个;但我将 运行 保持为 "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()
dice()
的结果是一个整数,您已将其命名为 rollOne
和 rollTwo
。
它们不能像您尝试做的那样 "called" rollOne()
。
为了解决错误,请从该行中删除括号(您在其他 if
语句中已这样做)
if rollOne() == rollTwo():
变成
if rollOne == rollTwo:
问题出在这里,
if rollOne() == rollTwo():
rollone 和 rolltwo 是 return 值而不是函数
我正在编写一个掷两个骰子的程序;然后根据掷出的东西分配分数;并保留 运行 总数。到目前为止,我有这个;但我将 运行 保持为 "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()
dice()
的结果是一个整数,您已将其命名为 rollOne
和 rollTwo
。
它们不能像您尝试做的那样 "called" rollOne()
。
为了解决错误,请从该行中删除括号(您在其他 if
语句中已这样做)
if rollOne() == rollTwo():
变成
if rollOne == rollTwo:
问题出在这里,
if rollOne() == rollTwo():
rollone 和 rolltwo 是 return 值而不是函数