Objects and Classes Exercise
Помощ хора! Задача 9 от Objects and Classes Exercise просто не иска да даде 100.
Изглежда супер лесна и не мога да си хвана грешката.
Задача:
Create a class Movie. The __init__ method should receive a name and a director. It should also have a default value of an attribute called watched set to False. There should also be a class attribute __watched_movies which will keep track of the number of all the watched movies. The class should have the following methods:
- change_name(new_name: str) - changes the name of the movie
- change_director(new_director: str) - changes the director of the movie
- watch() - change the watched attribute to True and increase the total watched movies class attribute (if the movie is not already watched)
- __repr__() - returns "Movie name: {name}; Movie director: {director}. Total watched movies: {__watched_movies}"
Example
Test Code |
Output |
first_movie = Movie("Inception", "Christopher Nolan") second_movie = Movie("The Matrix", "The Wachowskis") third_movie = Movie("The Predator", "Shane Black") first_movie.change_director("Me") third_movie.change_name("My Movie") first_movie.watch() third_movie.watch() first_movie.watch() print(first_movie) print(second_movie) print(third_movie) |
Movie name: Inception; Movie director: Me. Total watched movies: 2 Movie name: The Matrix; Movie director: The Wachowskis. Total watched movies: 2 Movie name: My Movie; Movie director: Shane Black. Total watched movies: 2 |
Решение:
https://pastebin.com/0Tt016Z8
Пробвах да сложа заглавията в лист в началото и да проверявам не само watched параметъра ами и дали заглавието е в листа (безсмислено по принцип) - и това не работи.
Благодаря предварително!