Hi all,
I am a bit stuck on how to fix my code. This is my first project so I do not have a lot of experience.
I keep getting the error message on the RHS, if anyone could provide guidance, that would be much appreciated!
Hi all,
I am a bit stuck on how to fix my code. This is my first project so I do not have a lot of experience.
I keep getting the error message on the RHS, if anyone could provide guidance, that would be much appreciated!
Welcome to the forums @Wiktoria_k. Please just post code and errors as text in code blocks or just this link to your project.
You classes are both missing __str__()
methods. Your big picture error message isn’t the correct message, your Square().set_side()
method does not actually set the side, and your Square()
class set_width()
and set_height()
methods are not implemented correctly (because they’re just implemented for rectangles and not squares).
Good luck.
Hello, @jeremy.a.gray ! Thank you for the warm welcome.
I have messed around with the code a bit more and seemed to fix some of the issues. However, I cannot get the code the print the picture properly! It just returns random symbols. I will paste my code below, and below that I will paste the outcome that I get.
Thank you for your help.
code
class Rectangle:
def init(self, width, height):
self.width = width
self.height = height
def __str__(self):
return f'Rectangle(width={self.width}, height={self.height})'
def set_width(self, width):
self.width = width
def set_height(self, height):
self.height = height
def get_picture(self):
if (self.width > 50 or self.height > 50):
return "Too big for picture."
picture = (("*" * self.width) + "\n") * self.height
return picture
def get_area(self):
return self.height * self.width
def get_perimeter(self):
return self.height * 2 + self.width * 2
def get_diagonal(self):
return ((self.height ** 2 + self.width ** 2) ** .5)
def get_amount_inside(self, shape):
return int(self.get_area() / shape.get_area())
class Square(Rectangle):
def init(self, side):
self.width = side
self.height = side
def __str__(self):
return f'Square(side={self.width})'
def set_side(self, side):
self.width = side
self.height = side
output
Ran 15 tests in 0.001s
Your output suggests you are passing all tests without issue.
What exactly is your problem?
For this project I am expected to get an outcome which shows a rectangle shape formed with ‘*’ , however for the output I am receiving just a straight line of multiple ‘.’ and ‘-’.
Dunno what output you are talking about…
In case you mean the final line in the output: those are your testresults. A dot means you passed a test. Only dots means you passed all tests.
If you want to see a rectangle, you need to print it somewhere. The built-in tests only check if your rectangle is designed correctly, but they don’t print it out, hence nothing to see.
Okay, thank you for your replies!
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.