-1
I started studying object-oriented programming in Python this week and did an exercise but I don’t know if it’s right. I need someone to take a look at it to point out my mistakes because although the code is working, it is different from what appears in the feedback. Here is the exercise:
Square Class: Create a class that models a square:
Attributes: Side Size
Methods: Change Side Value, Return Side Value, and Calculate Area.
class Quadrado():
def __init__(self, x):
self.tamanho_lado = x
def mudar_val_lado(self, novo_lado):
x = novo_lado
self.tamanho_lado = novo_lado
def retorna_val_lado(self, x):
self.tamanho_lado = x
print(x)
def calc_area(self, x):
self.tamanho_lado = x
print(x*x)
carreau = Quadrado(5)
print(carreau.tamanho_lado)
carreau.mudar_val_lado(4)
print(carreau.tamanho_lado)
carreau.retorna_val_lado(3)
carreau.calc_area(5)
Thanks for the tips. I tried to avoid the mistakes that were pointed out.
– Regis Tossou