Tell us what’s happening:
Describe your issue in detail here.
I did the code on a different python terminal and the code works as intended so i copy and paste it back into the console but there are weird [object object] things after the ‘*’ and it prints them on different lines and i got no idea how to solve it.
There is the problem with the ‘None’ that im attempting to fix
Your code so far
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
self.side = None
def __str__(self):
message = 'Rectangle(width={}, height={})'.format(self.width, self.height)
return message
def set_height(self, height):
self.height = height
def set_width(self, width):
self.width = width
def get_area(self):
area = self.width * self.height
return area
def get_perimeter(self):
perimeter = 2 * self.width + 2 * self.height
return perimeter
def get_diagonal(self):
diagonal = (self.width ** 2 + self.height ** 2) ** .5
return diagonal
def get_picture(self):
for _ in range(self.height):
count_width = 0
while count_width != self.width:
print('*',end="")
count_width += 1
print('\n')
def get_amount_inside(self, square):
self.side = square.side
heightsq = self.height//self.side
widthsq = self.width // self.side
if heightsq > 0 and widthsq > 0:
return heightsq * widthsq
else:
print('None')
class Square:
def __init__(self, side):
self.height = None
self.width = None
self.side = side
def __str__(self):
message = 'Square(side={})'.format(self.side)
return message
def set_side(self, side):
self.side = side
def get_area(self):
area = self.side ** 2
return area
def get_perimeter(self):
perimeter = self.side * 4
return perimeter
def get_diagonal(self):
diagonal = (self.side ** 2 + self.side ** 2) ** .5
return diagonal
def get_picture(self):
for _ in range(self.side):
count_side = 0
while count_side != self.side:
print('*',end=" ")
count_side += 1
print('\n')
rect = Rectangle(10, 5)
print(rect.get_area())
rect.set_height(3)
print(rect.get_perimeter())
print(rect)
print(rect.get_picture())
sq = Square(9)
print(sq.get_area())
sq.set_side(4)
print(sq.get_diagonal())
print(sq)
print(sq.get_picture())
rect.set_height(8)
rect.set_width(16)
print(rect.get_amount_inside(sq))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Scientific Computing with Python Projects - Polygon Area Calculator