+ 1
Python core 73.3 Calculating volume
class Rectangle: def __init__(self, width, height): self.w = width self.h = height def vol(self): # return volume w = int(input()) h = int(input()) obj = Rectangle(w, h) #call the function """Im not understanding how to calculate the volume, I understand w*h=vol but how do i plug that into the function"""
8 Respuestas
+ 8
William Alley ,
you need to print the result:
...
print(obj.vol())
+ 2
William Alley
#volume
self.w * self.h
#calling function
obj.vol()
+ 2
Thank you Lothar this Practice module just made me doubt everything ive been learning because i didnt plug the obj.vol() into print()
+ 1
class Rectangle:
def __init__(self, width, height):
self.w = width
self.h = height
def vol(self):
volume = self.w * self.h
return volume
# return volume
w = int(input())
h = int(input())
obj = Rectangle(w, h)
#call the function
obj.vol()
+ 1
It didnt work
0
This works 100%.
class Rectangle:
def __init__(self, width, height):
self.w = width
self.h = height
def vol(self):
# return volume
return width*height
w = int(input())
h = int(input())
obj = Rectangle(w, h)
#call the function
print(w*h)
0
class Rectangle:
def __init__(self, width, height):
self.w = width
self.h = height
def vol(self):
# return volume
return width*height
w = int(input())
h = int(input())
obj = Rectangle(w, h)
#call the function
print(w*h)
0
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def vol(self):
return self.width * self.height
w = int(input())
h = int(input())
volume = Rectangle(w, h)
print(volume.vol())