+ 2

Problem with Classes

class Rectangle: def __int__(self,width,height): self.width=width self.height=height width= input() height= input() Rect= Rectangle(width,height) volume=int(w)*int(h) print(volume) Why is telling me that Rectangle() takes no arguements

22nd Dec 2020, 7:50 PM
Sean
Sean - avatar
4 Respuestas
+ 6
Sean , also variables "w" and "h" are not defined. If you create a class, it's better to create method in the class for volume calculation. Look at the code. Hope it helps you. https://code.sololearn.com/c3c98MatPAX6/?ref=app
22nd Dec 2020, 8:06 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 4
you have .. def __int__(self,width,height): you need .. def __init__(self, width, height):....your missing the last 'i' in __init__.
22nd Dec 2020, 8:03 PM
rodwynnejones
rodwynnejones - avatar
+ 3
Better to add the Python tag to your question.
22nd Dec 2020, 8:51 PM
Sonic
Sonic - avatar
+ 1
class Rectangle: def __init__(self, width, height): self.w = width self.h = height def vol(self): return self.w * self.h w = int(input()) h = int(input()) Quadrilateral = Rectangle(w, h) print (Quadrilateral.vol()) Try this approach!
30th Jun 2021, 11:41 AM
Aaditya