+ 1
Invalid syntax
class Geaom(object): def__init__(self,h = 10,w = 10): self.h, self.w = h def rectangle(self): rect = self.h*2 + self.w*2 return rect a = Geom(4) print(a.rectangle()) This is a quiz from python challenge. On idle it show invalid syntax at line 2 def__init__(self, h= 10, w = 10): for this semicolon. why so?
2 Réponses
+ 2
make this changes-
line 2: space between def and _init_
line 3: replace comma (,) with equal to (=)
line 7: spelling mistake, it should be "Geaom"
line 7: pass 2 arguments instead of 1
+ 1
class Geaom(object):
def __init__(self,h = 10,w = 10):
self.h = self.w = h
def rectangle(self):
rect = self.h*2 + self.w*2
return rect
a = Geaom(50, 60)
print(a.rectangle())