'int' object is not callable

后端 未结 3 1670
北荒
北荒 2021-01-14 04:47

I\'m trying to define a simply Fraction class

And I\'m getting this error:

python fraction.py 
Traceback (most recent call last):
File          


        
3条回答
  •  甜味超标
    2021-01-14 05:10

    You're using numerator as both a method name (def numerator(...)) and member variable name (self.numerator = n). Use set_numerator and set_denominator for the method names and it will work.

    By the way, Python 2.6 has a built-in fraction class.

提交回复
热议问题