Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """PR11 Drawing."""
- # TODO: You should create the exception classes here.
- class FigureDoesNotExistError(Exception):
- """IF figure does not exist"""
- pass
- class DrawingFullError(Exception):
- """IF drawing figures are full."""
- pass
- class DrawingCanvas:
- """A drawing canvas where one can draw some simple figures."""
- def __init__(self, max_figures: int, author: str):
- """
- Initialize the canvas.
- You should initialize your variables (properties) here.
- :param max_figures: The maxim amount of figures on the drawing.
- :param author: The author of the drawing.
- """
- self.max_figures = max_figures
- self.author = author
- self.figures = []
- self.figures_count = 0
- def draw_figure(self, figure: str) -> str or None:
- """
- Draw a new figure.
- If the drawing has already reached maximum amount of figures
- don't add this figure and throw a DrawingFullError with the
- message "The drawing is full".
- There can be only unique figures on the drawing.
- This means that there is no way that, for example, two or more
- circles are on the drawing.
- In this case method does nothing and returns None.
- :param figure: A figure to draw.
- :return: The newly drawn figure.
- """
- self.figures_count += 1
- if self.figures_count > self.max_figures:
- self.figures_count -= 1
- raise DrawingFullError("The drawing is full")
- for i in self.figures:
- if i == figure:
- self.figures_count =- 1
- return None
- return figure
- def erase_figure(self, figure: str) -> str:
- """
- Erase the figure.
- If there is no such figure throw a FigureDoesNotExistError
- with the message "There is no such figure on the drawing".
- :return: The erased figure.
- """
- try:
- self.figures.index(figure)
- except ValueError:
- raise FigureDoesNotExistError("There is no such figure on the drawing")
- self.figures.remove(figure)
- self.figures_count -= 1
- return figure
- def is_empty(self) -> bool:
- """
- Find out whether the drawing is empty or not.
- Empty means there are not any figures drawn on it.
- :return: True if empty, False otherwise.
- """
- if self.figures == []:
- return True
- else:
- return False
- def size(self) -> int:
- """Return the amount of figures on the drawing."""
- return len(self.figures)
- def __str__(self):
- """
- A string representation of the drawing.
- The returned string must follow this pattern:
- "The drawing painted by {author}. Contains {current amount of figures} figure(s)"
- :return: A correct string representing the drawing.
- """
- return "The drawing painted by " + self.author + ". " + "Contains " + str(self.figures_count) + " figure(s)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement