0
Why is this not working?
I'm making this class, but it's saying that the arguments aren't defined! Why is this? https://code.sololearn.com/cQMVIWpSufyB/?ref=app
4 Answers
+ 4
Have a look at lesson 73 of the Python core course.
You haven't defined the properties and erroneously tried to inherit from non-existing nominator and deniminator classes
+ 1
AJ šŗš¦#PeaceForUkrainešŗš¦
Wrong syntax for class definition
You cannot make class with arguments instead you have to make constructor of class
With correction but there need some correction from your side
Also float or int is not iterable so you have to convert in str
-------
class Fraction:
def __init__(self, numerator, denominator):
self.numerator = numerator
self.denominator = denominator
def convertToDecimal ():
decimal = numerator / denominator
def simplify (self):
i = 2
while ("." in (str(self.numerator / i))) or ("." in (str(self.denominator / i))):
i += 1
if i > 500:
print("Error: cannot simplify " + str(self.numerator) + "/" + str(self.denominator) + "!")
newfraction = Fraction(100, 200)
newfraction.simplify()
0
Ok
0
Thanks