There is one error ii am not able to figure out

Tell us what’s happening:

Your code so far

class Rectangle():
    
  def __init__(self, width, height):
    self.width = width
    self.height = height
  
  def set_width(self, new_width):
    self.width = new_width
  def set_height(self, new_height):
    self.height = new_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 __str__(self):
    return(("Rectangle(width={0}, height={1})").format(self.width, self.height))


  def get_picture(self):
      if self.width > 50 or self.height > 50:
        return ("Too big for picture.")
      else:
         return ((("*" * self.width)+ "\n" )* self.height)

  def get_amount_inside(self,shape):
    shape_area = shape.get_area()
    home_area = self.get_area()
    count = 0
    while home_area > shape_area:
      home_area = home_area - shape_area
      count += 1
    return count
   

class Square(Rectangle):

  def __init__(self, side):
    Rectangle.width = side
    Rectangle.height = side
  
  def set_side(self, newside):
    Rectangle.width = newside
    Rectangle.height = newside

  def __str__(self):
    return (("Square(side={})".format(Rectangle.width)))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Probability Calculator

Link to the challenge:

Hi, what, error are you seeing?


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hey @nayankoshiya ,
I guess this method is responsible for the error that you’re facing. I think you need to set the value of newside with the methods set_width and set_height as below:

  def set_side(self, newside):
    Rectangle.set_width(self, newside)
    Rectangle.set_height(self, newside)

This should fix the problem. Check it.

Hi Jeremy and Sonu Saha,

The error points to line 100 of code in the test module. Where it is saying the function get_amount_inside is not returning the expected valued

Can you share the link to your repl for this project?

Hi dear,

Here is the link

https://repl.it/@NayanKoshiya/fcc-shape-calculator-1

Also here is the snap

Hey there,

good work so far!

There is also an error in line 69 I would try to fix first.

You set self.sq.set_side(2) but actual = str(self.sq) doesn’t lead to the correct answer.

Hi miku86,

Still I am getting error…

Hi,
if you could check into the repl - https://repl.it/join/cuyphbqh-nayankoshiya

Hi @nayankoshiya
There were two minor errors in your code that were causing the problem. One was a logical error and another was a syntactical error on lines number 35 and 52 respectively.
Below is a screenshot:


The reason you need to put greater than equal to because you can accommodate another shape even if the area is equal and that makes the termination condition. The syntax error is self-explanatory.
After fixing those errors your code was running all good. Below is a screenshot which shows that it passed all the test cases.

PS: Correct the errors in your repl, I forked your repl so no changes have been made to the original code.

I hope this helps.
Happy coding!
Cheers :sunglasses:

1 Like

Hi dear ,

Thanks a lot…often silly things. However, I would like to understand the last solution. i often confused how to use or call Methods and variables defined inside a class.

when we say “.format( self.width)” which line in the code it will refer to…?

Thanks a lot!
Nayan

@nayankoshiya when you say self.width it means width of the object which has called the method.
And .format is the string formatting syntax.

1 Like