Python - TypeError: 'int' object is not callable

前端 未结 2 1000
滥情空心
滥情空心 2021-01-20 16:11

(Using Python 2.7)

Hello,

I\'ve two version of a class PairOfDice.

1.) This one is not working and throws an error.

TypeErro

2条回答
  •  长发绾君心
    2021-01-20 16:19

    This is because you have a property called total, as well as a function called total. When you run roll, you are overwriting the class's definition of total.

    In other words, before you run roll, player1.total is a function. However, once you run roll, you set player1.total to be a number. From then on, when you reference player1.total, you are referring to that number.

    You might want to rename the total function to something like getTotal, or something similar.

提交回复
热议问题