I am having an issue with a project due. I am missing something? can you please help?
here are the instructions and what i have so far.
The final project will consist of three files called, Shape.py, Circle.py, and Square.py. I’ve written a test file you can use to see if your code is working correctly.
Create the files Shape.py, Circle.py, and Square.py. Each file will contain one class.
Shape.py will contain the Shape class. This will be the base class for the Circle and Square classes.
The Shape class contains a class attribute called shape_name, x, and y. Create a constructor method (initialization method). This method creates and initializes x and y. x and y represent a point where the shape is. The shape_name attribute is a name that you create when you instantiate a Circle or a Square.
Create the __str__ method in the Shape class that returns a string that contains the name of the shape and the x and y values.
Create a move method in the Shape class that accepts two values. These values are added to x and y to simulate moving the shape.
The Circle class is based on the Shape class. Create a constructor that accepts a name, x and y as well as a radius. Also create a __str__method and a method called area. The area method returns radius * radius * 3.14159.
The Square class is based on the Shape class. Create a constructor that accepts a name, x and y as well as a side. Also create a __str__method and a method called area. The area method returns side * side.
The Circle and Square classes init method must call the Shape init method.
The Circle and Square classes str method calls Shape’s str method.
Here’s some code to test your classes:
# main
from Circle import Circle
from Square import Square
circle = Circle("aCircle", 2, 2, 3)
square = Square("aSquare", 0, 0, 4)
print circle
print square
print circle.area()
print square.area()
circle.move(-1, -2)
print circle
square.move(2, 3)
print square
Here is my base file Shape.py
# Shape Class
import Square, Circle
class Shape(object):
def __init__(self, x, y):
self.pos = x, y
def move(self, Circle, Square):
x, y = self.pos
self.pos = x + shape_name, y + shape_name
# main
from Circle import Circle
from Square import Square
circle = Circle("aCircle", 2, 2, 3)
square = Square("aSquare", 0, 0, 4)
print circle
print square
print circle.area()
print square.area()
circle.move(-1, -2)
print circle
square.move(2, 3)
print square
HERE IS WHAT I HAVE FOR CIRCLE.PY
#circle class
class Circle(Shape):
"""Circle Class"""
Circle = ["Circle"]
def __init__(self, shape, x, y, radius):
super(Circle, self).__init__(Circle)
self.radius = radius
def __str__(self):
rep = self.Circle
return rep
AND SQUARE.PY
# Square Class
class Square(object):
"""Square Class"""
Square = ["Square"]
def __init__(self, x, y, shape_name, side):
super(Square, self).__init__(Square)
self.side = side
def __str__(self):
rep = self.name
return rep
the following error is returned:
Traceback (most recent call last):
File "C:\Users\Guess Who\Desktop\Programing Class\Shape.py", line 25, in -toplevel-
print circle
TypeError: __str__ returned non-string (type list)
thank you