Scientific Computing with Python Projects - Polygon Area Calculator

Tell us what’s happening:

Do we no longer use replit for running the tests? I’ve passed all but two tests on this one but the current system of running the tests on the project description page doesn’t tell me what is wrong with my output. Help would be appreciated.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36

Challenge Information:

Scientific Computing with Python Projects - Polygon Area Calculator

no, we don’t use replit anymore. Can you share your code?

Hi,
Thank you for your reply.
My 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_area(self):
    return self.width * self.height

  def get_perimeter(self):
    return 2 * self.width + 2 * self.height

  def get_diagonal(self):
    return (self.width ** 2 + self.height ** 2) ** .5

  def get_picture(self):
    count = 0
    string = '*'
    line = string * self.width
    result = f''
    if self.width > 50:
      return 'Too big for picture.'
    elif self.height > 50:
      return 'Too big for picture.'
    else:
      pass
    while count < self.height:
      if count == 0:
        result = f'{line}'
      else:
        result = f'{result}\n{line}'
      count += 1
    return result

  def get_amount_inside(self, shape):
    x = self.width // shape.width
    y = self.height // shape.height
    return (x * y)

class Square(Rectangle):
  def __init__(self, side):
    self.side = side
    self.width = self.side
    self.height = self.side

  def __str__(self):
    return f'Square(side={self.side})'

  def set_side(self, side):
    self.side = side
    self.width = side
    self.height = side
  
  def set_height(self, height):
    self.set_side(height)

  def set_width(self, width):
    self.set_side(width)
  • get_picture: Returns a string that represents the shape using lines of “". The number of lines should be equal to the height and the number of "” in each line should be equal to the width. There should be a new line (\n) at the end of each line. If the width or height is larger than 50, this should return the string: “Too big for picture.”.

That means also at the end of last line I guess

Thank you for helping, it worked

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.