Created
May 28, 2016 08:27
-
-
Save rksys/3a41a2e5451e548143a809a32ea4a7f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __truedive__(self,fraction): | |
if fraction.numerator == 0: | |
print('Cannot divide by 0') | |
exit() | |
else: | |
return(Fraction(self.numerator*fraction.denominator,self.denominator*fraction.numerator)) |
给学生的回答
你的"魔法方法名错了", 应该用__truediv__
.
魔法方法名错误的结果就是, python解释器在运行 a/b
的时候, 操作符/
会找不到对应的魔法方法
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
学生的出错信息: