Python core 73.3 Calculating volume | Sololearn: Learn to code for FREE!
+ 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"""

3rd Jan 2022, 5:22 PM
William Alley
William Alley - avatar
8 Answers
+ 8
William Alley , you need to print the result: ... print(obj.vol())
3rd Jan 2022, 5:48 PM
Lothar
Lothar - avatar
+ 2
William Alley #volume self.w * self.h #calling function obj.vol()
3rd Jan 2022, 5:31 PM
A͢J
A͢J - avatar
+ 2
Thank you Lothar this Practice module just made me doubt everything ive been learning because i didnt plug the obj.vol() into print()
3rd Jan 2022, 5:59 PM
William Alley
William Alley - avatar
+ 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()
3rd Jan 2022, 5:39 PM
William Alley
William Alley - avatar
+ 1
It didnt work
3rd Jan 2022, 5:39 PM
William Alley
William Alley - avatar
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)
18th Mar 2022, 12:17 PM
Adigun Kazeem
Adigun Kazeem - avatar
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)
18th Mar 2022, 12:35 PM
Adigun Kazeem
Adigun Kazeem - avatar
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())
25th Mar 2022, 10:01 PM
Matumbai Binale
Matumbai Binale - avatar