Rectangular cube class
Write a class that receives rectangular length, width and height and calculates its area and volume using different methods
Write a class that receives rectangular length, width and height and calculates its area and volume using different methods
class RectangularPrism: @staticmethod def calculate_surface_area(length, width, height): return 2 * (length * width + length * height + width * height) @staticmethod def calculate_volume(length, width, height): return length * width * height if __name__ == "__main__": while True: try: length = float(input("لطفاً طول مکعب مستطیل را وارد کنید: ")) width = float(input("لطفاً عرض مکعب مستطیل را وارد کنید: ")) height = float(input("لطفاً ارتفاع مکعب مستطیل را وارد کنید: ")) break except ValueError: print("لطفاً یک عدد صحیح یا اعشاری وارد کنید.") surface_area = RectangularPrism.calculate_surface_area(length, width, height) volume = RectangularPrism.calculate_volume(length, width, height) print(f"مساحت سطح مکعب مستطیل: {surface_area} واحد مربع") print(f"حجم مکعب مستطیل: {volume} واحد مکعب")
class Cube: # The definition of the class and the proportions
def __init__(self, length, width, height):
self.length = length
self.width = width
self.height = height
def area(self): # The area method
A = (self.width * self.height + self.length *
self.height + self.length * self.width) * 2
return f"\narea = {A}\n"
def volume(self): # The volume method
V = self.height * self.width * self.length
return f"\nvolume = {V}\n"
A_and_V = int(input("\narea ---> 1 & volume ---> 2 : "))
# Be one or two. The area or volume is displayed a_and_v. If
if A_and_V == 1 or A_and_V == 2:
# Get the length, width and height
l = float(input("\nlength : "))
w = float(input("\nwidth : "))
h = float(input("\nheight : "))
cobe = Cube(l, w, h) #object
if A_and_V == 1: # If 1 is the area displayed
print(cobe.area())
elif A_and_V == 2: # If 2 volume is displayed
print(cobe.volume())
# Otherwise the following text will be printed
else:
print("\nThere are only 2 options !! (1 and 2)\n")
class x: def __init__(self , tool , arz , artefa): self.tool=tool self.arz=arz self.artefa=artefa def masahat(self): print(self.tool*self.arz*6) def hajm(self): print(self.tool*self.arz*self.artefa) while True: k=input("1.adame 2.laghv :") if k=="2": break elif k=="1": t=float(input("tool:")) a=float(input("arz:")) ar=float(input("artefa:")) m=x(t , a , ar) i=input("1.masahat 2.hajm :") if i=="1": m.masahat() elif i=="2": m.hajm() else: print("error") else: print("error")
class maht: def __init__(self,a,b,c): self.a=a self.b=b self.c=c def math_h(self): return(f'The volume of a rectangular cube is equal to:{self.a*self.b*self.c}') a1=int(input('enter length:')) b1=int(input('enter width:')) c1=int(input('enter height:')) ob =maht(a1,b1,c1) print(ob.math_h())
class MokabMostatil: def __init__(self,x,y,z): self.x=x self.y=y self.z=z def hajm(self): return self.x*self.y*self.z def masahat(self): return 2*self.x*self.y+2*self.x*self.z+2*self.y*self.z
class RectangularPrism: def __init__(self, length, width, height): self.length = length self.width = width self.height = height def surface_area(self): """محاسبه مساحت سطح مکعب مستطیل""" return 2 * (self.length * self.width + self.length * self.height + self.width * self.height) def volume(self): """محاسبه حجم مکعب مستطیل""" return self.length * self.width * self.height if __name__ == "__main__": # Get the length, width and height of the user while True: try: length = float(input("لطفاً طول مکعب مستطیل را وارد کنید: ")) width = float(input("لطفاً عرض مکعب مستطیل را وارد کنید: ")) height = float(input("لطفاً ارتفاع مکعب مستطیل را وارد کنید: ")) break except ValueError: print("لطفاً یک عدد صحیح یا اعشاری وارد کنید.") # Creating an object from the Rectangularprism class prism = RectangularPrism(length, width, height) # Calculation and display area and volume print(f"مساحت سطح مکعب مستطیل: {prism.surface_area()} واحد مربع") print(f"حجم مکعب مستطیل: {prism.volume()} واحد مکعب")
class Mm: def __init__(self , ertefaa , arz , tool): self.ertefaa = ertefaa self.arz = arz self.tool = tool def hajm(self): return self.arz * self.tool * self.ertefaa def masahat(self): j = 2 * (self.ertefaa * self.arz + self.ertefaa * self.tool + self.arz * self.tool) return j a = Mm(int(input("Ertefaa :")) , int(input("Arz :")) , int(input("Tool :"))) print("mashat :" ,a.masahat()) print() print("hajm :" ,a.hajm())
class Cube: def __init__(self,length,width,hight): self.length = length self.width = width self.hight = hight def area(self): return 2 * ((self.length * self.width) + (self.length * self.hight) + (self.hight * self.width)) def volume(self): return self.length * self.width * self.hight l = int(input('length(cm): ')) w = int(input('width(cm): ')) h = int(input('hight(cm): ')) cube = Cube(l,w,h) print(f'area: {cube.area()}cm2 \nvolume: {cube.volume()}cm3')
# Rectangular cube class class RectangularPrism: def __init__(self,H,L,W): self.H = H self.L = L self.W = W def V(self): return(self.H*self.L*self.W) def S(self): return 2*((W*L)+(W*H)+(L*H)) try: H = float(input("height: ")) L = float(input("length: ")) W = float(input("width: ")) except ValueError: print("Please enter a number") R = RectangularPrism(H,L,W) print('V:',R.V()) print('S:',R.S())
class Mokaabe_mostatil: def __init__(self,tul,arz,ertefa): self.tul=tul self.arz=arz self.ertefa=ertefa def mohasebe_masahat(self): return self.arz*self.tul def mohasebe_hajm(self): return self.arz*self.tul*self.ertefa m=Mokaabe_mostatil(10,5,5) print(m.mohasebe_masahat()) print(m.mohasebe_hajm())
Submitting answers is currently unavailable.
Style the FIX class using CSS to constantly place in the lower left corner of the screen (10 pixels) and the position does not change if the user scrolls.
Define a class of User that has a username, email and password and the following methods. Print: Print username and email in the output IS_Gmail: Check whether the user's email is Gmail and ...
Write a program that receives a student's lessons and the number of each unit (receiving the score and the number of units until the number is 0).
Write a program that receives a one -digit number from the input and finds the coefficient of smaller than 100 of those numbers and prints in the output
Write a program where the user can enter the number of one -digit number and then all the numbers that can print the construction with the entered digits for example: Input: 1 input: 2 input: End 12 21 11 22
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.