├── .idea ├── .gitignore ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── mooc-programming-22.iml └── vcs.xml ├── Readme.md ├── course_config.toml ├── part08 ├── part08-01_smallest_average │ ├── .tmcproject.yml │ ├── src │ │ └── smallest_average.py │ ├── test │ │ ├── __init__.py │ │ └── test_smallest_average.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-02_row_sums │ ├── .tmcproject.yml │ ├── src │ │ └── row_sums.py │ ├── test │ │ ├── __init__.py │ │ └── test_row_sums.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-03_list_years │ ├── .tmcproject.yml │ ├── src │ │ └── list_years.py │ ├── test │ │ ├── __init__.py │ │ └── test_list_years.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-04_shopping_list │ ├── .tmcproject.yml │ ├── src │ │ └── shopping_list.py │ ├── test │ │ ├── __init__.py │ │ └── test_shopping_list.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-05_book │ ├── .tmcproject.yml │ ├── src │ │ └── book.py │ ├── test │ │ ├── __init__.py │ │ └── test_book.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-06_three_classes │ ├── .tmcproject.yml │ ├── src │ │ └── three_classes.py │ ├── test │ │ ├── __init__.py │ │ └── test_three_classes.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-07_pet │ ├── .tmcproject.yml │ ├── src │ │ └── pet.py │ ├── test │ │ ├── __init__.py │ │ └── test_pet.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-08_older_book │ ├── .tmcproject.yml │ ├── src │ │ └── older_book.py │ ├── test │ │ ├── __init__.py │ │ └── test_older_book.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-09_books_of_genre │ ├── .tmcproject.yml │ ├── src │ │ └── books_of_genre.py │ ├── test │ │ ├── __init__.py │ │ └── test_books_of_genre.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-10_decreasing_counter │ ├── .tmcproject.yml │ ├── src │ │ └── decreasing_counter.py │ ├── test │ │ ├── __init__.py │ │ └── test_decreasing_counter.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-11_first_and_last_name │ ├── .tmcproject.yml │ ├── src │ │ └── first_and_last_name.py │ ├── test │ │ ├── __init__.py │ │ └── test_first_and_last_name.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-12_number_stats │ ├── .tmcproject.yml │ ├── src │ │ └── number_stats.py │ ├── test │ │ ├── __init__.py │ │ └── test_number_stats.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-13_stopwatch │ ├── .tmcproject.yml │ ├── src │ │ └── stopwatch.py │ ├── test │ │ ├── __init__.py │ │ └── test_stopwatch.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-14_clock │ ├── .tmcproject.yml │ ├── src │ │ └── clock.py │ ├── test │ │ ├── __init__.py │ │ └── test_clock.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part08-15_lunchcard │ ├── .tmcproject.yml │ ├── src │ │ └── lunchcard.py │ ├── test │ │ ├── __init__.py │ │ └── test_lunchcard.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py └── part08-16_series │ ├── .tmcproject.yml │ ├── src │ └── series.py │ ├── test │ ├── __init__.py │ └── test_series.py │ └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part09 ├── part09-01_fastest_car │ ├── .tmcproject.yml │ ├── src │ │ └── fastest_car.py │ ├── test │ │ ├── __init__.py │ │ └── test_fastest_car.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-02_passing_submissions │ ├── .tmcproject.yml │ ├── src │ │ └── passing_submissions.py │ ├── test │ │ ├── __init__.py │ │ └── test_passing_submissions.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-03_baby_centre │ ├── .tmcproject.yml │ ├── src │ │ └── baby_centre.py │ ├── test │ │ ├── __init__.py │ │ └── test_baby_centre.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-04_lunchcard_and_paymentterminal │ ├── .tmcproject.yml │ ├── src │ │ └── lunchcard_and_paymentterminal.py │ ├── test │ │ ├── __init__.py │ │ └── test_lunchcard_and_paymentterminal.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-05_comparing_properties │ ├── .tmcproject.yml │ ├── src │ │ └── comparing_properties.py │ ├── test │ │ ├── __init__.py │ │ └── test_comparing_properties.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-06_pets │ ├── .tmcproject.yml │ ├── src │ │ └── pets.py │ ├── test │ │ ├── __init__.py │ │ └── test_pets.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-07_box_of_presents │ ├── .tmcproject.yml │ ├── src │ │ └── box_of_presents.py │ ├── test │ │ ├── __init__.py │ │ └── test_box_of_presents.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-08_shortest_in_room │ ├── .tmcproject.yml │ ├── src │ │ └── shortest_in_room.py │ ├── test │ │ ├── __init__.py │ │ └── test_shortest_in_room.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-09_car │ ├── .tmcproject.yml │ ├── src │ │ └── car.py │ ├── test │ │ ├── __init__.py │ │ └── test_car.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-10_recording │ ├── .tmcproject.yml │ ├── src │ │ └── recording.py │ ├── test │ │ ├── __init__.py │ │ └── test_recording.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-11_weather_station │ ├── .tmcproject.yml │ ├── src │ │ └── weather_station.py │ ├── test │ │ ├── __init__.py │ │ └── test_weather_station.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-12_service_charge │ ├── .tmcproject.yml │ ├── src │ │ └── service_charge.py │ ├── test │ │ ├── __init__.py │ │ └── test_service_charge.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-13_postcodes │ ├── .tmcproject.yml │ ├── src │ │ └── postcodes.py │ ├── test │ │ ├── __init__.py │ │ └── test_postcodes.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part09-14_list_helper │ ├── .tmcproject.yml │ ├── src │ │ └── list_helper.py │ ├── test │ │ ├── __init__.py │ │ └── test_list_helper.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py └── part09-15_item_suitcase_hold │ ├── .tmcproject.yml │ ├── src │ └── code.py │ ├── test │ ├── __init__.py │ ├── test_1_item.py │ ├── test_2_suitcase.py │ └── test_3_cargo_hold.py │ └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part10 ├── part10-01_laptop_computer │ ├── .tmcproject.yml │ ├── src │ │ └── laptop_computer.py │ ├── test │ │ ├── __init__.py │ │ └── test_laptop_computer.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-02_game_museum │ ├── .tmcproject.yml │ ├── src │ │ └── game_museum.py │ ├── test │ │ ├── __init__.py │ │ └── test_game_museum.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-03_areas │ ├── .tmcproject.yml │ ├── src │ │ └── areas.py │ ├── test │ │ ├── __init__.py │ │ └── test_areas.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-04_word_game │ ├── .tmcproject.yml │ ├── src │ │ └── word_game.py │ ├── test │ │ ├── __init__.py │ │ └── test_word_game.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-05_supergroup │ ├── .tmcproject.yml │ ├── src │ │ └── supergroup.py │ ├── test │ │ ├── __init__.py │ │ └── test_supergroup.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-06_secret_magic_potion │ ├── .tmcproject.yml │ ├── src │ │ └── secret_magic_potion.py │ ├── test │ │ ├── __init__.py │ │ └── test_secret_magic_potion.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-07_money │ ├── .tmcproject.yml │ ├── src │ │ └── money.py │ ├── test │ │ ├── __init__.py │ │ └── test_money.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-08_simple_date │ ├── .tmcproject.yml │ ├── src │ │ └── simple_date.py │ ├── test │ │ ├── __init__.py │ │ └── test_simple_date.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-09_iterable_shopping_list │ ├── .tmcproject.yml │ ├── src │ │ └── iterable_shopping_list.py │ ├── test │ │ ├── __init__.py │ │ └── test_iterable_shopping_list.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-10_phone_book_v1 │ ├── .tmcproject.yml │ ├── luettelo.txt │ ├── phonebook.txt │ ├── src │ │ ├── phone_book_v1.py │ │ └── phonebook.txt │ ├── test │ │ ├── __init__.py │ │ └── test_phone_book_v1.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part10-11_phone_book_v2 │ ├── .tmcproject.yml │ ├── src │ │ └── phone_book_v2.py │ ├── test │ │ ├── __init__.py │ │ ├── test_phone_book_v2_1.py │ │ ├── test_phone_book_v2_2.py │ │ └── test_phone_book_v2_3.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py └── part10-12_course_records │ ├── .tmcproject.yml │ ├── src │ └── course_records.py │ ├── test │ ├── __init__.py │ └── test_course_records.py │ └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part11 ├── part11-01_square_roots │ ├── .tmcproject.yml │ ├── src │ │ └── square_roots.py │ ├── test │ │ ├── __init__.py │ │ └── test_square_roots.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-02_rows_of_stars │ ├── .tmcproject.yml │ ├── src │ │ └── rows_of_stars.py │ ├── test │ │ ├── __init__.py │ │ └── test_rows_of_stars.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-03_best_exam_result │ ├── .tmcproject.yml │ ├── src │ │ └── best_exam_result.py │ ├── test │ │ ├── __init__.py │ │ └── test_best_exam_result.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-04_lengths │ ├── .tmcproject.yml │ ├── src │ │ └── lengths.py │ ├── test │ │ ├── __init__.py │ │ └── test_lengths.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-05_remove_smaller_than │ ├── .tmcproject.yml │ ├── src │ │ └── remove_smaller_than.py │ ├── test │ │ ├── __init__.py │ │ └── test_remove_smaller_than.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-06_begin_with_vowel │ ├── .tmcproject.yml │ ├── src │ │ └── begin_with_vowel.py │ ├── test │ │ ├── __init__.py │ │ └── test_begin_with_vowel.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-07_lottery_numbers │ ├── .tmcproject.yml │ ├── src │ │ └── lottery_numbers.py │ ├── test │ │ ├── __init__.py │ │ └── test_lottery_numbers.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-08_filter_forbidden │ ├── .tmcproject.yml │ ├── src │ │ └── filter_forbidden.py │ ├── test │ │ ├── __init__.py │ │ └── test_filter_forbidden.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-09_products_in_shopping_list │ ├── .tmcproject.yml │ ├── src │ │ └── products_in_shopping_list.py │ ├── test │ │ ├── __init__.py │ │ └── test_products_in_shopping_list.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-10_cheaper_properties │ ├── .tmcproject.yml │ ├── src │ │ └── cheaper_properties.py │ ├── test │ │ ├── __init__.py │ │ └── test_cheaper_properties.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-11_lengths_of_strings │ ├── .tmcproject.yml │ ├── src │ │ └── lengths_of_strings.py │ ├── test │ │ ├── __init__.py │ │ └── test_lengths_of_strings.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-12_most_common_words │ ├── .tmcproject.yml │ ├── comprehensions.txt │ ├── programming.txt │ ├── src │ │ ├── comprehensions.txt │ │ ├── most_common_words.py │ │ └── programming.txt │ ├── test │ │ ├── __init__.py │ │ └── test_most_common_words.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-13_add_numbers_to_list │ ├── .tmcproject.yml │ ├── src │ │ └── add_numbers_to_list.py │ ├── test │ │ ├── __init__.py │ │ └── test_add_numbers_to_list.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-14_recursive_sum │ ├── .tmcproject.yml │ ├── src │ │ └── recursive_sum.py │ ├── test │ │ ├── __init__.py │ │ └── test_recursive_sum.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-15_balanced_brackets │ ├── .tmcproject.yml │ ├── src │ │ └── balanced_brackets.py │ ├── test │ │ ├── __init__.py │ │ └── test_balanced_brackets.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-16_greatest_node │ ├── .tmcproject.yml │ ├── src │ │ └── greatest_node.py │ ├── test │ │ ├── __init__.py │ │ └── test_greatest_node.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-17_bosses_and_subordinates │ ├── .tmcproject.yml │ ├── src │ │ └── bosses_and_subordinates.py │ ├── test │ │ ├── __init__.py │ │ └── test_bosses_and_subordinates.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part11-18_order_book │ ├── .tmcproject.yml │ ├── src │ │ └── order_book.py │ ├── test │ │ ├── __init__.py │ │ ├── test_order_book1.py │ │ ├── test_order_book2.py │ │ ├── test_order_book3.py │ │ └── test_task.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py └── part11-19_order_book_application │ ├── .tmcproject.yml │ ├── src │ └── order_book_application.py │ ├── test │ ├── __init__.py │ ├── test_order_book_application1.py │ └── test_order_book_application2.py │ └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part12 ├── part12-01_remaining_stock │ ├── .tmcproject.yml │ ├── src │ │ └── remaining_stock.py │ ├── test │ │ ├── __init__.py │ │ └── test_remaining_stock.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-02_seasons │ ├── .tmcproject.yml │ ├── src │ │ └── seasons.py │ ├── test │ │ ├── __init__.py │ │ └── test_seasons.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-03_ratings │ ├── .tmcproject.yml │ ├── src │ │ └── ratings.py │ ├── test │ │ ├── __init__.py │ │ └── test_ratings.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-04_climbing_route │ ├── .tmcproject.yml │ ├── src │ │ └── climbing_route.py │ ├── test │ │ ├── __init__.py │ │ └── test_climbing_route.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-05_climbing_areas │ ├── .tmcproject.yml │ ├── src │ │ └── climbing_areas.py │ ├── test │ │ ├── __init__.py │ │ └── test_climbing_areas.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-06_ballplayers │ ├── .tmcproject.yml │ ├── src │ │ └── ballplayers.py │ ├── test │ │ ├── __init__.py │ │ └── test_ballplayers.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-07_product_search │ ├── .tmcproject.yml │ ├── src │ │ └── product_search.py │ ├── test │ │ ├── __init__.py │ │ └── test_product_search.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-08_even_numbers │ ├── .tmcproject.yml │ ├── src │ │ └── even_numbers.py │ ├── test │ │ ├── __init__.py │ │ └── test_even_numbers.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-09_prime_numbers │ ├── .tmcproject.yml │ ├── src │ │ └── prime_numbers.py │ ├── test │ │ ├── __init__.py │ │ └── test_prime_numbers.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-10_random_words │ ├── .tmcproject.yml │ ├── src │ │ └── random_words.py │ ├── test │ │ ├── __init__.py │ │ └── test_random_words.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-11_attempted_courses │ ├── .tmcproject.yml │ ├── src │ │ └── attempted_courses.py │ ├── test │ │ ├── __init__.py │ │ └── test_attempted_courses.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-12_filtering_attempts │ ├── .tmcproject.yml │ ├── src │ │ └── filtering_attempts.py │ ├── test │ │ ├── __init__.py │ │ └── test_filtering_attempts.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-13_credits │ ├── .tmcproject.yml │ ├── src │ │ └── credits.py │ ├── test │ │ ├── __init__.py │ │ └── test_credits.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py ├── part12-14_regular_expressions │ ├── .tmcproject.yml │ ├── src │ │ └── regular_expressions.py │ ├── test │ │ ├── __init__.py │ │ └── test_regular_expressions.py │ └── tmc │ │ ├── __init__.py │ │ ├── __main__.py │ │ ├── django.py │ │ ├── points.py │ │ ├── reflect.py │ │ ├── result.py │ │ ├── runner.py │ │ └── utils.py └── part12-15_hockey_statistics │ ├── .tmcproject.yml │ ├── all.json │ ├── partial.json │ ├── src │ ├── all.json │ ├── hockey_statistics.py │ └── partial.json │ ├── test │ ├── __init__.py │ ├── test_hockey_statistics1.py │ ├── test_hockey_statistics2.py │ └── test_hockey_statistics3.py │ └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py └── part13 ├── part13-01_four_robots ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-02_robots_row ├── .tmcproject.yml ├── robot.png ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-03_hundred_robots ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-04_random_robots ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-05_vertical_movement ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-06_round_the_perimeter ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-07_two_robots ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-08_robot_circle ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-09_bouncing_ball ├── .tmcproject.yml ├── src │ ├── ball.png │ └── main.py ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-10_robot_invasion ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-11_four_directions ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-12_four_walls ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-13_two_players ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-14_robot_and_mouse ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-15_robot_location ├── .tmcproject.yml ├── src │ ├── main.py │ └── robot.png ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py ├── part13-16_clock ├── .tmcproject.yml ├── src │ └── main.py ├── test │ ├── __init__.py │ └── test_main.py └── tmc │ ├── __init__.py │ ├── __main__.py │ ├── django.py │ ├── points.py │ ├── reflect.py │ ├── result.py │ ├── runner.py │ └── utils.py └── part13-17_asteroids ├── .tmcproject.yml ├── src ├── main.py ├── robot.png └── rock.png ├── test ├── __init__.py └── test_main.py └── tmc ├── __init__.py ├── __main__.py ├── django.py ├── points.py ├── reflect.py ├── result.py ├── runner.py └── utils.py /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/mooc-programming-22.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /part08/part08-01_smallest_average/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-01_smallest_average/src/smallest_average.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | def smallest_average(person1: dict, person2: dict, person3: dict): 3 | avg = [] 4 | p1_avg = (person1['result1'] + person1['result2'] + person1['result3'])/3 5 | p2_avg = (person2['result1'] + person2['result2'] + person2['result3'])/3 6 | p3_avg = (person3['result1'] + person3['result2'] + person3['result3'])/3 7 | 8 | avg.append(p1_avg) 9 | avg.append(p2_avg) 10 | avg.append(p3_avg) 11 | 12 | smallest = min(avg) 13 | 14 | if smallest == p1_avg: 15 | return person1 16 | elif smallest == p2_avg: 17 | return person2 18 | elif smallest == p3_avg: 19 | return person3 20 | else: 21 | return {} 22 | 23 | 24 | if __name__ == "__main__": 25 | person1 = {"name": "Mary", "result1": 2, "result2": 3, "result3": 3} 26 | person2 = {"name": "Gary", "result1": 5, "result2": 1, "result3": 8} 27 | person3 = {"name": "Larry", "result1": 3, "result2": 1, "result3": 1} 28 | 29 | print(smallest_average(person1, person2, person3)) -------------------------------------------------------------------------------- /part08/part08-01_smallest_average/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-01_smallest_average/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-01_smallest_average/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-01_smallest_average/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-02_row_sums/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-02_row_sums/src/row_sums.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | def row_sums(my_matrix: list): 3 | for row in my_matrix: 4 | row.append(sum(row)) 5 | 6 | if __name__ == "__main__": 7 | my_matrix = [[1, 2], [3, 4]] 8 | row_sums(my_matrix) 9 | print(my_matrix) -------------------------------------------------------------------------------- /part08/part08-02_row_sums/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-02_row_sums/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-02_row_sums/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-02_row_sums/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-02_row_sums/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-03_list_years/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-03_list_years/src/list_years.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | # Remember the import statement 3 | # from datetime import date 4 | 5 | from datetime import * 6 | 7 | def list_years(dates: list): 8 | year_list=[] 9 | 10 | for item in dates: 11 | year_list.append(item.year) 12 | 13 | year_list.sort() 14 | 15 | return year_list 16 | 17 | 18 | if __name__ == "__main__": 19 | date1 = date(2019, 2, 3) 20 | date2 = date(2006, 10, 10) 21 | date3 = date(1993, 5, 9) 22 | 23 | years = list_years([date1, date2, date3]) 24 | print(years) -------------------------------------------------------------------------------- /part08/part08-03_list_years/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-03_list_years/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-03_list_years/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-03_list_years/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-03_list_years/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-04_shopping_list/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-04_shopping_list/src/shopping_list.py: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE THE CODE OF THE CLASS 2 | # ShoppingList. Write yous solution under it! 3 | class ShoppingList: 4 | def __init__(self): 5 | self.products = [] 6 | 7 | def number_of_items(self): 8 | return len(self.products) 9 | 10 | def add(self, product: str, number: int): 11 | self.products.append((product, number)) 12 | 13 | def item(self, n: int): 14 | return self.products[n - 1][0] 15 | 16 | def amount(self, n: int): 17 | return self.products[n - 1][1] 18 | 19 | # ------------------------- 20 | # Write your solution here: 21 | # ------------------------- 22 | 23 | def total_units(my_list : list): 24 | unit = 0 25 | for i in range(1, my_list.number_of_items()+1): 26 | unit += my_list.amount(i) 27 | 28 | return unit 29 | 30 | if __name__ == "__main__": 31 | my_list = ShoppingList() 32 | my_list.add("bananas", 10) 33 | my_list.add("apples", 5) 34 | my_list.add("pineapple", 1) 35 | 36 | print(total_units(my_list)) -------------------------------------------------------------------------------- /part08/part08-04_shopping_list/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-04_shopping_list/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-04_shopping_list/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-04_shopping_list/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-04_shopping_list/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-05_book/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-05_book/src/book.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | class Book: 3 | 4 | def __init__(self, name : str, author : str, genre : str, year : int): 5 | self.name = name 6 | self.author = author 7 | self.genre = genre 8 | self.year = year 9 | 10 | 11 | if __name__ == "__main__": 12 | python = Book("Fluent Python", "Luciano Ramalho", "programming", 2015) 13 | everest = Book("High Adventure", "Edmund Hillary", "autobiography", 1956) 14 | 15 | print(f"{python.author}: {python.name} ({python.year})") 16 | print(f"The genre of the book {everest.name} is {everest.genre}") -------------------------------------------------------------------------------- /part08/part08-05_book/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-05_book/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-05_book/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-05_book/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-05_book/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-06_three_classes/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-06_three_classes/src/three_classes.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | 3 | class Checklist: 4 | def __init__(self, header : str, entries : list): 5 | self.header = header 6 | self.entries = entries 7 | 8 | class Customer: 9 | def __init__(self, id : str, balance : bool, discount : int): 10 | self.id = id 11 | self.balance = balance 12 | self.discount = discount 13 | 14 | class Cable: 15 | def __init__(self, model : str, length : float, max_speed : int, bidirectional : bool): 16 | self.model = model 17 | self.length = length 18 | self.max_speed = max_speed 19 | self.bidirectional = bidirectional -------------------------------------------------------------------------------- /part08/part08-06_three_classes/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-06_three_classes/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-06_three_classes/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-06_three_classes/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-06_three_classes/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-07_pet/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-07_pet/src/pet.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | class Pet: 3 | def __init__(self, name : str, species : str, year_of_birth : int): 4 | self.name = name 5 | self.species = species 6 | self.year_of_birth = year_of_birth 7 | 8 | def new_pet(name : str, species : str, year_of_birth : int): 9 | new_pet = Pet(name, species, year_of_birth) 10 | return new_pet 11 | 12 | if __name__ == "__main__": 13 | fluffy = new_pet("Fluffy", "dog", 2017) 14 | print(fluffy.name) 15 | print(fluffy.species) 16 | print(fluffy.year_of_birth) -------------------------------------------------------------------------------- /part08/part08-07_pet/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-07_pet/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-07_pet/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-07_pet/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-07_pet/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-08_older_book/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-08_older_book/src/older_book.py: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE CLASS Book! 2 | # Write your solution after the class! 3 | 4 | class Book: 5 | def __init__(self, name: str, author: str, genre: str, year: int): 6 | self.name = name 7 | self.author = author 8 | self.genre = genre 9 | self.year = year 10 | 11 | def older_book(obj1 : Book, obj2 : Book): 12 | if obj1.year > obj2.year: 13 | print(f"{obj2.name} is older, it was published in {obj2.year}") 14 | elif obj1.year == obj2.year: 15 | print(f"{obj1.name} and {obj2.name} were published in {obj1.year}") 16 | else: 17 | print(f"{obj1.name} is older, it was published in {obj1.year}") 18 | 19 | # ----------------------------- 20 | # Write your solution here 21 | # ----------------------------- 22 | if __name__ == "__main__": 23 | 24 | python = Book("Fluent Python", "Luciano Ramalho", "programming", 2015) 25 | everest = Book("High Adventure", "Edmund Hillary", "autobiography", 1956) 26 | norma = Book("Norma", "Sofi Oksanen", "crime", 2015) 27 | 28 | older_book(python, everest) 29 | older_book(python, norma) -------------------------------------------------------------------------------- /part08/part08-08_older_book/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-08_older_book/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-08_older_book/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-08_older_book/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-08_older_book/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-09_books_of_genre/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-09_books_of_genre/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-09_books_of_genre/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-09_books_of_genre/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-09_books_of_genre/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-10_decreasing_counter/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-10_decreasing_counter/src/decreasing_counter.py: -------------------------------------------------------------------------------- 1 | # Tee ratkaisusi tähän: 2 | class DecreasingCounter: 3 | def __init__(self, initial_value: int): 4 | self.value = initial_value 5 | self.initial_value = initial_value 6 | 7 | def print_value(self): 8 | print("value:", self.value) 9 | 10 | def decrease(self): 11 | if self.value > 0: 12 | self.value -= 1 13 | else: 14 | self.value = 0 15 | 16 | def set_to_zero(self): 17 | self.value = 0 18 | 19 | def reset_original_value(self): 20 | self.value = self.initial_value 21 | 22 | # Write the rest of the methods here! 23 | 24 | if __name__ == "__main__": 25 | counter = DecreasingCounter(55) 26 | counter.decrease() 27 | counter.decrease() 28 | counter.decrease() 29 | counter.decrease() 30 | counter.print_value() 31 | counter.reset_original_value() 32 | counter.print_value() 33 | -------------------------------------------------------------------------------- /part08/part08-10_decreasing_counter/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-10_decreasing_counter/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-10_decreasing_counter/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-10_decreasing_counter/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-11_first_and_last_name/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-11_first_and_last_name/src/first_and_last_name.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | 3 | class Person: 4 | def __init__(self, name : str): 5 | self.name = name 6 | 7 | def return_first_name(self): 8 | return self.name.split(' ')[0] 9 | 10 | def return_last_name(self): 11 | return self.name.split(' ')[1] 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | if __name__ == "__main__": 20 | peter = Person("Peter Pythons") 21 | print(peter.return_first_name()) 22 | print(peter.return_last_name()) 23 | 24 | paula = Person("Paula Pythonnen") 25 | print(paula.return_first_name()) 26 | print(paula.return_last_name()) 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /part08/part08-11_first_and_last_name/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-11_first_and_last_name/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-11_first_and_last_name/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-11_first_and_last_name/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-12_number_stats/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-12_number_stats/src/number_stats.py: -------------------------------------------------------------------------------- 1 | # Write your solution here! 2 | class NumberStats: 3 | def __init__(self): 4 | self.numbers = [] 5 | 6 | def add_number(self, number:int): 7 | self.numbers.append(number) 8 | 9 | def count_numbers(self): 10 | return len(self.numbers) 11 | 12 | def get_sum(self): 13 | return sum(self.numbers) if len(self.numbers) > 0 else 0 14 | 15 | def average(self): 16 | return sum(self.numbers)/len(self.numbers) if len(self.numbers) > 0 else 0 17 | 18 | print('Please type in integer numbers:') 19 | stats = NumberStats() 20 | evens = NumberStats() 21 | odds = NumberStats() 22 | while True: 23 | number = int(input('')) 24 | if number == -1: 25 | break 26 | stats.add_number(number) 27 | evens.add_number(number) if number%2==0 else odds.add_number(number) 28 | 29 | print(f'Sum of numbers: {stats.get_sum()}') 30 | print(f'Mean of numbers: {stats.average()}') 31 | print(f'Sum of even numbers: {evens.get_sum()}') 32 | print(f'Sum of odd numbers: {odds.get_sum()}') -------------------------------------------------------------------------------- /part08/part08-12_number_stats/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-12_number_stats/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-12_number_stats/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-12_number_stats/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-12_number_stats/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-13_stopwatch/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-13_stopwatch/src/stopwatch.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | class Stopwatch: 3 | def __init__(self): 4 | self.seconds = 0 5 | self.minutes = 0 6 | 7 | def tick(self): 8 | self.seconds += 1 9 | if self.seconds == 60: 10 | self.seconds = 0 11 | self.minutes += 1 12 | if self.minutes == 60: 13 | self.minutes = 0 14 | 15 | def __str__(self): 16 | return f'{self.minutes:02d}:{self.seconds:02d}' 17 | -------------------------------------------------------------------------------- /part08/part08-13_stopwatch/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-13_stopwatch/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-13_stopwatch/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-13_stopwatch/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-13_stopwatch/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-14_clock/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-14_clock/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-14_clock/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-14_clock/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-14_clock/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-14_clock/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-15_lunchcard/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-15_lunchcard/src/lunchcard.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | class LunchCard: 3 | def __init__(self, balance: float): 4 | self.balance = balance 5 | 6 | def __str__(self): 7 | return f'The balance is {self.balance:.1f} euros' 8 | 9 | def eat_lunch(self): 10 | if (self.balance-2.60) > 0: 11 | self.balance -= 2.60 12 | 13 | def eat_special(self): 14 | if (self.balance-4.60) > 0: 15 | self.balance -= 4.60 16 | 17 | def deposit_money(self, amount: float): 18 | if amount < 0: 19 | raise ValueError('You cannot deposit an amount of money less than zero') 20 | self.balance += amount 21 | 22 | peters_card = LunchCard(20) 23 | graces_card = LunchCard(30) 24 | peters_card.eat_special() 25 | graces_card.eat_lunch() 26 | print(f'Peter: {peters_card}') 27 | print(f'Grace: {graces_card}') 28 | peters_card.deposit_money(20) 29 | graces_card.eat_special() 30 | print(f'Peter: {peters_card}') 31 | print(f'Grace: {graces_card}') 32 | peters_card.eat_lunch() 33 | peters_card.eat_lunch() 34 | graces_card.deposit_money(50) 35 | print(f'Peter: {peters_card}') 36 | print(f'Grace: {graces_card}') -------------------------------------------------------------------------------- /part08/part08-15_lunchcard/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-15_lunchcard/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-15_lunchcard/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-15_lunchcard/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-15_lunchcard/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part08/part08-16_series/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part08/part08-16_series/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part08/part08-16_series/test/__init__.py -------------------------------------------------------------------------------- /part08/part08-16_series/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part08/part08-16_series/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part08/part08-16_series/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part09/part09-01_fastest_car/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-01_fastest_car/src/fastest_car.py: -------------------------------------------------------------------------------- 1 | # Write your solution after the class Car 2 | # Do not make changes to the class! 3 | class Car: 4 | def __init__(self, make: str, top_speed: int): 5 | self.make = make 6 | self.top_speed = top_speed 7 | 8 | def __str__(self): 9 | return f"Car (make: {self.make}, top speed: {self.top_speed})" 10 | 11 | # WRITE YOUR SOLUTION HERE: 12 | 13 | def fastest_car(cars: list): 14 | fastest = cars[0] 15 | for car in cars: 16 | if car.top_speed > fastest.top_speed: 17 | fastest = car 18 | return fastest.make 19 | 20 | if __name__ == "__main__": 21 | car1 = Car("Saab", 195) 22 | car2 = Car("Lada", 110) 23 | car3 = Car("Ferrari", 280) 24 | car4 = Car("Trabant", 85) 25 | 26 | cars = [car1, car2, car3, car4] 27 | print(fastest_car(cars)) -------------------------------------------------------------------------------- /part09/part09-01_fastest_car/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-01_fastest_car/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-01_fastest_car/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-01_fastest_car/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-01_fastest_car/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part09/part09-02_passing_submissions/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-02_passing_submissions/src/passing_submissions.py: -------------------------------------------------------------------------------- 1 | # Write your solution after the class ExamSubmission 2 | # Do not make changes to the class! 3 | class ExamSubmission: 4 | def __init__(self, examinee: str, points: int): 5 | self.examinee = examinee 6 | self.points = points 7 | 8 | def __str__(self): 9 | return f'ExamSubmission (examinee: {self.examinee}, points: {self.points})' 10 | 11 | # # WRITE YOUR SOLUTION HERE: 12 | def passed(submissions: list, lowest_passing: int): 13 | passed_list = [] 14 | 15 | for sub in submissions: 16 | if sub.points >= lowest_passing: 17 | passed_list.append(sub) 18 | return passed_list 19 | 20 | if __name__ == "__main__": 21 | s1 = ExamSubmission("Peter", 12) 22 | s2 = ExamSubmission("Pippa", 19) 23 | s3 = ExamSubmission("Paul", 15) 24 | s4 = ExamSubmission("Phoebe", 9) 25 | s5 = ExamSubmission("Persephone", 17) 26 | 27 | passes = passed([s1, s2, s3, s4, s5], 15) 28 | for passing in passes: 29 | print(passing) -------------------------------------------------------------------------------- /part09/part09-02_passing_submissions/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-02_passing_submissions/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-02_passing_submissions/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-02_passing_submissions/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-03_baby_centre/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-03_baby_centre/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-03_baby_centre/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-03_baby_centre/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-03_baby_centre/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-03_baby_centre/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part09/part09-04_lunchcard_and_paymentterminal/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-04_lunchcard_and_paymentterminal/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-04_lunchcard_and_paymentterminal/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-04_lunchcard_and_paymentterminal/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-04_lunchcard_and_paymentterminal/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-05_comparing_properties/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-05_comparing_properties/src/comparing_properties.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | 3 | import re 4 | 5 | 6 | class RealProperty: 7 | def __init__(self, rooms: int , square_metres: int , price_per_sqm:int): 8 | self.rooms = rooms 9 | self.square_metres = square_metres 10 | self.price_per_sqm = price_per_sqm 11 | 12 | def bigger(self, compared_to:'RealProperty'): 13 | return self.square_metres > compared_to.square_metres 14 | 15 | def get_total_price(self): 16 | return self.square_metres*self.price_per_sqm 17 | 18 | def price_difference(self, compared_to:'RealProperty'): 19 | return abs(self.get_total_price() - compared_to.get_total_price()) 20 | 21 | def more_expensive(self, compared_to:'RealProperty'): 22 | return self.get_total_price() > compared_to.get_total_price() 23 | 24 | if __name__ == "__main__": 25 | central_studio = RealProperty(1, 16, 5500) 26 | downtown_two_bedroom = RealProperty(2, 38, 4200) 27 | suburbs_three_bedroom = RealProperty(3, 78, 2500) 28 | 29 | print(central_studio.bigger(downtown_two_bedroom)) 30 | print(suburbs_three_bedroom.bigger(downtown_two_bedroom)) -------------------------------------------------------------------------------- /part09/part09-05_comparing_properties/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-05_comparing_properties/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-05_comparing_properties/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-05_comparing_properties/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-06_pets/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-06_pets/src/pets.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | 3 | class Pet: 4 | def __init__(self, name: str, description: str): 5 | self.name = name 6 | self.description = description 7 | 8 | def __str__(self): 9 | return f"{self.name} ({self.description})" 10 | 11 | class Person: 12 | def __init__(self, name: str, pet: Pet): 13 | self.name = name 14 | self.pet = pet 15 | 16 | def __str__(self): 17 | return self.name + ", whose pal is " + self.pet.name + ", a " + self.pet.description 18 | 19 | 20 | if __name__ == "__main__": 21 | hulda = Pet("Hulda", "mixed-breed dog") 22 | levi = Person("Levi", hulda) 23 | 24 | print(levi) -------------------------------------------------------------------------------- /part09/part09-06_pets/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-06_pets/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-06_pets/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-06_pets/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-06_pets/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part09/part09-07_box_of_presents/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-07_box_of_presents/src/box_of_presents.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | 3 | class Present(): 4 | def __init__(self, name : str, weight : int): 5 | self.name = name 6 | self.weight = weight 7 | 8 | def __str__(self): 9 | return f'{self.name} ({self.weight} kg)' 10 | 11 | class Box(): 12 | def __init__(self): 13 | self.present_list = [] 14 | 15 | def add_present(self, present: Present): 16 | self.present_list.append(present) 17 | 18 | def total_weight(self): 19 | sum = 0 20 | for present in self.present_list: 21 | sum += present.weight 22 | return sum 23 | 24 | if __name__ == "__main__": 25 | book = Present("ABC Book", 2) 26 | 27 | box = Box() 28 | box.add_present(book) 29 | print(box.total_weight()) 30 | 31 | cd = Present("Pink Floyd: Dark Side of the Moon", 1) 32 | box.add_present(cd) 33 | print(box.total_weight()) -------------------------------------------------------------------------------- /part09/part09-07_box_of_presents/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-07_box_of_presents/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-07_box_of_presents/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-07_box_of_presents/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-08_shortest_in_room/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-08_shortest_in_room/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-08_shortest_in_room/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-08_shortest_in_room/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-08_shortest_in_room/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-09_car/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-09_car/src/car.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class Car: 3 | def __init__(self): 4 | self.__petrol = 0 5 | self.__odometer = 0 6 | 7 | def fill_up(self): 8 | self.__petrol = 60 9 | 10 | def drive(self, km: int): 11 | if km <= self.__petrol: 12 | self.__petrol -= km 13 | self.__odometer += km 14 | else: 15 | self.__odometer += self.__petrol 16 | self.__petrol = 0 17 | 18 | def __str__(self): 19 | return f'Car: odometer reading {self.__odometer} km, petrol remaining {self.__petrol} litres' 20 | 21 | if __name__ == "__main__": 22 | car = Car() 23 | print(car) 24 | car.fill_up() 25 | print(car) 26 | car.drive(20) 27 | print(car) 28 | car.drive(50) 29 | print(car) 30 | car.drive(10) 31 | print(car) 32 | car.fill_up() 33 | car.fill_up() 34 | print(car) 35 | -------------------------------------------------------------------------------- /part09/part09-09_car/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-09_car/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-09_car/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-09_car/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-09_car/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part09/part09-10_recording/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-10_recording/src/recording.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class Recording: 3 | def __init__(self, length : int): 4 | if length < 0: 5 | raise ValueError('Length of recording cannot be below 0.') 6 | self.__length = length 7 | 8 | @property 9 | def length(self): 10 | return self.__length 11 | 12 | @length.setter 13 | def length(self, new_length : int): 14 | if new_length < 0: 15 | raise ValueError('Length of recording cannot be below 0.') 16 | self.__length = new_length 17 | 18 | if __name__ == "__main__": 19 | the_wall = Recording(43) 20 | print(the_wall.length) 21 | the_wall.length = 44 22 | print(the_wall.length) -------------------------------------------------------------------------------- /part09/part09-10_recording/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-10_recording/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-10_recording/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-10_recording/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-11_weather_station/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-11_weather_station/src/weather_station.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class WeatherStation: 3 | def __init__(self, name : str): 4 | self.__name = name 5 | self.__my_list = [] 6 | 7 | def add_observation(self, observation: str): 8 | self.__my_list.append(observation) 9 | 10 | def number_of_observations(self): 11 | return len(self.__my_list) 12 | 13 | def latest_observation(self): 14 | if self.number_of_observations() == 0: 15 | return '' 16 | else: 17 | return self.__my_list[-1] 18 | 19 | def __str__(self): 20 | return f'{self.__name}, {len(self.__my_list)} observations' 21 | 22 | 23 | if __name__ == "__main__": 24 | station = WeatherStation("Houston") 25 | station.add_observation("Rain 10mm") 26 | station.add_observation("Sunny") 27 | print(station.latest_observation()) 28 | 29 | station.add_observation("Thunderstorm") 30 | print(station.latest_observation()) 31 | 32 | print(station.number_of_observations()) 33 | print(station) 34 | -------------------------------------------------------------------------------- /part09/part09-11_weather_station/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-11_weather_station/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-11_weather_station/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-11_weather_station/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-12_service_charge/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-12_service_charge/src/service_charge.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class BankAccount: 3 | def __init__(self, owner : str, account_number : str, balance : float): 4 | self.__owner = owner 5 | self.__account_number = account_number 6 | self.__balance = balance 7 | 8 | @property 9 | def balance(self): 10 | return self.__balance 11 | 12 | def __service_charge(self): 13 | service_charge = self.__balance * 0.01 14 | self.__balance -= service_charge 15 | 16 | def deposit(self, amount: float): 17 | self.__balance += amount 18 | self.__service_charge() 19 | 20 | def withdraw(self, amount: float): 21 | self.__balance -= amount 22 | self.__service_charge() 23 | 24 | if __name__ == "__main__": 25 | account = BankAccount("Randy Riches", "12345-6789", 1000) 26 | account.withdraw(100) 27 | print(account.balance) 28 | account.deposit(100) 29 | print(account.balance) 30 | 31 | -------------------------------------------------------------------------------- /part09/part09-12_service_charge/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-12_service_charge/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-12_service_charge/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-12_service_charge/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-13_postcodes/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-13_postcodes/src/postcodes.py: -------------------------------------------------------------------------------- 1 | # Add the requested members to the class below: 2 | 3 | class City: 4 | 5 | postcodes = { 6 | 'Helsinki' : '00100', 7 | 'Turku' : '20100', 8 | 'Tampere' : '33100', 9 | 'Rovaniemi' : '96100', 10 | 'Oulu' : '90100' 11 | } 12 | 13 | 14 | def __init__(self, name: str, population: int): 15 | self.__name = name 16 | self.__population = population 17 | 18 | @property 19 | def name(self): 20 | return self.__name 21 | 22 | @property 23 | def population(self): 24 | return self.__population 25 | 26 | def __str__(self): 27 | return f"{self.__name} ({self.__population} residents.)" 28 | -------------------------------------------------------------------------------- /part09/part09-13_postcodes/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-13_postcodes/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-13_postcodes/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-13_postcodes/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-14_list_helper/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-14_list_helper/src/list_helper.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class ListHelper: 3 | @classmethod 4 | def greatest_frequency(cls, my_list: list): 5 | greatest_count = 1 6 | greatest_count_element = my_list[0] 7 | for element in my_list: 8 | if my_list.count(element) > greatest_count: 9 | greatest_count = my_list.count(element) 10 | greatest_count_element = element 11 | return greatest_count_element 12 | 13 | @classmethod 14 | def doubles(cls, my_list: list): 15 | my_set = set(my_list) 16 | count_at_least_double = 0 17 | for element in my_set: 18 | if my_list.count(element) >= 2: 19 | count_at_least_double += 1 20 | return count_at_least_double 21 | 22 | 23 | if __name__ == "__main__": 24 | numbers = [1, 1, 2, 1, 3, 3, 4, 5, 5, 5, 6, 5, 5, 5] 25 | print(ListHelper.greatest_frequency(numbers)) 26 | print(ListHelper.doubles(numbers)) -------------------------------------------------------------------------------- /part09/part09-14_list_helper/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-14_list_helper/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-14_list_helper/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-14_list_helper/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part09/part09-15_item_suitcase_hold/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part09/part09-15_item_suitcase_hold/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part09/part09-15_item_suitcase_hold/test/__init__.py -------------------------------------------------------------------------------- /part09/part09-15_item_suitcase_hold/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part09/part09-15_item_suitcase_hold/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-01_laptop_computer/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-01_laptop_computer/src/laptop_computer.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | class Computer: 3 | def __init__(self, model: str, speed: int): 4 | self.__model = model 5 | self.__speed = speed 6 | 7 | @property 8 | def model(self): 9 | return self.__model 10 | 11 | @property 12 | def speed(self): 13 | return self.__speed 14 | 15 | class LaptopComputer(Computer): 16 | def __init__(self, model: str, speed: int, weight: int): 17 | super().__init__(model, speed) 18 | self.weight = weight 19 | 20 | def __str__(self): 21 | return f'{self.model}, {self.speed} MHz, {self.weight} kg' 22 | 23 | if __name__ == '__main__': 24 | laptop = LaptopComputer("NoteBook Pro15", 1500, 2) 25 | print(laptop) 26 | -------------------------------------------------------------------------------- /part10/part10-01_laptop_computer/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-01_laptop_computer/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-01_laptop_computer/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-01_laptop_computer/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-02_game_museum/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-02_game_museum/src/game_museum.py: -------------------------------------------------------------------------------- 1 | # TEE RATKAISUSI TÄHÄN: 2 | class ComputerGame: 3 | def __init__(self, name: str, publisher: str, year: int): 4 | self.name = name 5 | self.publisher = publisher 6 | self.year = year 7 | 8 | class GameWarehouse: 9 | def __init__(self): 10 | self.__games = [] 11 | 12 | def add_game(self, game: ComputerGame): 13 | self.__games.append(game) 14 | 15 | def list_games(self): 16 | return self.__games 17 | 18 | class GameMuseum(GameWarehouse): 19 | def __init__(self): 20 | super().__init__() 21 | 22 | def list_games(self): 23 | games = super().list_games() 24 | old_games = [] 25 | for game in games: 26 | if game.year < 1990: 27 | old_games.append(game) 28 | return old_games 29 | 30 | 31 | 32 | if __name__ == "__main__": 33 | museum = GameMuseum() 34 | museum.add_game(ComputerGame("Pacman", "Namco", 1980)) 35 | museum.add_game(ComputerGame("GTA 2", "Rockstar", 1999)) 36 | museum.add_game(ComputerGame("Bubble Bobble", "Taito", 1986)) 37 | for game in museum.list_games(): 38 | print(game.name) 39 | -------------------------------------------------------------------------------- /part10/part10-02_game_museum/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-02_game_museum/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-02_game_museum/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-02_game_museum/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-03_areas/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-03_areas/src/areas.py: -------------------------------------------------------------------------------- 1 | # Write your solution here! 2 | class Rectangle: 3 | def __init__(self, width: int, height: int): 4 | self.width = width 5 | self.height = height 6 | 7 | def __str__(self): 8 | return f"rectangle {self.width}x{self.height}" 9 | 10 | def area(self): 11 | return self.width * self.height 12 | 13 | class Square(Rectangle): 14 | def __init__(self, side): 15 | super().__init__(side, side) 16 | 17 | def __str__(self): 18 | return f'square {self.width}x{self.height}' 19 | 20 | if __name__ == "__main__": 21 | square = Square(4) 22 | print(square) 23 | print("area:", square.area()) -------------------------------------------------------------------------------- /part10/part10-03_areas/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-03_areas/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-03_areas/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-03_areas/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-03_areas/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part10/part10-04_word_game/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-04_word_game/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-04_word_game/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-04_word_game/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-04_word_game/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-05_supergroup/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-05_supergroup/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-05_supergroup/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-05_supergroup/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-05_supergroup/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-06_secret_magic_potion/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-06_secret_magic_potion/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-06_secret_magic_potion/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-06_secret_magic_potion/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-06_secret_magic_potion/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-07_money/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-07_money/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-07_money/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-07_money/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-07_money/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-07_money/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part10/part10-08_simple_date/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-08_simple_date/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-08_simple_date/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-08_simple_date/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-08_simple_date/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-09_iterable_shopping_list/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-09_iterable_shopping_list/src/iterable_shopping_list.py: -------------------------------------------------------------------------------- 1 | # TEE RATKAISUSI TÄHÄN: 2 | class ShoppingList: 3 | def __init__(self): 4 | self.products = [] 5 | 6 | def number_of_items(self): 7 | return len(self.products) 8 | 9 | def add(self, product: str, number: int): 10 | self.products.append((product, number)) 11 | 12 | def product(self, n: int): 13 | return self.products[n - 1][0] 14 | 15 | def number(self, n: int): 16 | return self.products[n - 1][1] 17 | 18 | def __iter__(self): 19 | self.iterator_index = 0 20 | return self 21 | 22 | def __next__(self): 23 | if self.iterator_index < len(self.products): 24 | product = self.products[self.iterator_index] 25 | self.iterator_index += 1 26 | return product 27 | else: 28 | raise StopIteration 29 | 30 | if __name__ == "__main__": 31 | shopping_list = ShoppingList() 32 | shopping_list.add("bananas", 10) 33 | shopping_list.add("apples", 5) 34 | shopping_list.add("pineapple", 1) 35 | 36 | for product in shopping_list: 37 | print(f"{product[0]}: {product[1]} units") 38 | -------------------------------------------------------------------------------- /part10/part10-09_iterable_shopping_list/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-09_iterable_shopping_list/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-09_iterable_shopping_list/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-09_iterable_shopping_list/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-10_phone_book_v1/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-10_phone_book_v1/luettelo.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-10_phone_book_v1/luettelo.txt -------------------------------------------------------------------------------- /part10/part10-10_phone_book_v1/phonebook.txt: -------------------------------------------------------------------------------- 1 | Erkki;02-123456;02-123456;02-123456;02-123456;02-123456;02-123456;02-123456;02-123456 2 | Emilia;09-123456;045-333444;09-123456;045-333444;09-123456;045-333444 3 | -------------------------------------------------------------------------------- /part10/part10-10_phone_book_v1/src/phonebook.txt: -------------------------------------------------------------------------------- 1 | Erkki;02-2 2 | -------------------------------------------------------------------------------- /part10/part10-10_phone_book_v1/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-10_phone_book_v1/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-10_phone_book_v1/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-10_phone_book_v1/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-11_phone_book_v2/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-11_phone_book_v2/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-11_phone_book_v2/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-11_phone_book_v2/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-11_phone_book_v2/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part10/part10-12_course_records/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part10/part10-12_course_records/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part10/part10-12_course_records/test/__init__.py -------------------------------------------------------------------------------- /part10/part10-12_course_records/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part10/part10-12_course_records/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-01_square_roots/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-01_square_roots/src/square_roots.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | 3 | import math 4 | 5 | 6 | def square_roots(numbers : list): 7 | return [math.sqrt(number) for number in numbers] 8 | 9 | if __name__ == "__main__": 10 | lines = square_roots([1,2,3,4]) 11 | for line in lines: 12 | print(line) -------------------------------------------------------------------------------- /part11/part11-01_square_roots/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-01_square_roots/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-01_square_roots/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-01_square_roots/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-02_rows_of_stars/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-02_rows_of_stars/src/rows_of_stars.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | def rows_of_stars(numbers : list): 3 | return [number * "*" for number in numbers] 4 | 5 | if __name__ == "__main__": 6 | rows = rows_of_stars([1,2,3,4]) 7 | for row in rows: 8 | print(row) 9 | 10 | print() 11 | 12 | rows = rows_of_stars([4, 3, 2, 1, 10]) 13 | for row in rows: 14 | print(row) -------------------------------------------------------------------------------- /part11/part11-02_rows_of_stars/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-02_rows_of_stars/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-02_rows_of_stars/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-02_rows_of_stars/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-03_best_exam_result/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-03_best_exam_result/src/best_exam_result.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class ExamResult: 3 | def __init__(self, name: str, grade1: int, grade2: int, grade3: int): 4 | self.name = name 5 | self.grade1 = grade1 6 | self.grade2 = grade2 7 | self.grade3 = grade3 8 | 9 | def __str__(self): 10 | return (f'Name:{self.name}, grade1: {self.grade1}' + 11 | f', grade2: {self.grade2}, grade3: {self.grade3}') 12 | 13 | def best_results( results : list): 14 | return [max([result.grade1, result.grade2, result.grade3]) for result in results] 15 | 16 | if __name__ == "__main__": 17 | result1 = ExamResult("Peter",5,3,4) 18 | result2 = ExamResult("Pippa",3,4,1) 19 | result3 = ExamResult("Paul",2,1,3) 20 | results = [result1, result2, result3] 21 | print(best_results(results)) 22 | -------------------------------------------------------------------------------- /part11/part11-03_best_exam_result/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-03_best_exam_result/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-03_best_exam_result/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-03_best_exam_result/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-04_lengths/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-04_lengths/src/lengths.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | def lengths(lists : list): 3 | return [ len(item) for item in lists] 4 | 5 | if __name__ == "__main__": 6 | lists = [[1,2,3,4,5], [324, -1, 31, 7],[]] 7 | print(lengths(lists)) -------------------------------------------------------------------------------- /part11/part11-04_lengths/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-04_lengths/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-04_lengths/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-04_lengths/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-04_lengths/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part11/part11-05_remove_smaller_than/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-05_remove_smaller_than/src/remove_smaller_than.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | 3 | def remove_smaller_than(numbers : list, limit : int): 4 | return [number for number in numbers if number >= limit] 5 | 6 | if __name__ == "__main__": 7 | numbers = [1,65, 32, -6, 9, 11] 8 | print(remove_smaller_than(numbers, 10)) 9 | 10 | print(remove_smaller_than([-4, 7, 8, -100], 0)) -------------------------------------------------------------------------------- /part11/part11-05_remove_smaller_than/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-05_remove_smaller_than/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-05_remove_smaller_than/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-05_remove_smaller_than/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-06_begin_with_vowel/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-06_begin_with_vowel/src/begin_with_vowel.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | def begin_with_vowel(words : list): 3 | return [word for word in words if word[0] in 'AEIOUaeiou'] 4 | 5 | if __name__ == "__main__": 6 | word_list = ["automobile","motorbike","Animal","cat","Dog","APPLE","orange"] 7 | for vowelled in begin_with_vowel(word_list): 8 | print(vowelled) -------------------------------------------------------------------------------- /part11/part11-06_begin_with_vowel/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-06_begin_with_vowel/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-06_begin_with_vowel/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-06_begin_with_vowel/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-07_lottery_numbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-07_lottery_numbers/src/lottery_numbers.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class LotteryNumbers: 3 | def __init__(self, week: int, numbers: list): 4 | self.__week = week 5 | self.__numbers = numbers 6 | 7 | def number_of_hits(self, numbers: list): 8 | return len([number for number in numbers if number in self.__numbers]) 9 | 10 | def hits_in_place(self, numbers: list): 11 | return [number if number in self.__numbers else -1 for number in numbers] 12 | 13 | if __name__ == "__main__": 14 | week5 = LotteryNumbers(5, [1,2,3,4,5,6,7]) 15 | my_numbers = [1,4,7,11,13,19,24] 16 | 17 | print(week5.number_of_hits(my_numbers)) -------------------------------------------------------------------------------- /part11/part11-07_lottery_numbers/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-07_lottery_numbers/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-07_lottery_numbers/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-07_lottery_numbers/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-08_filter_forbidden/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-08_filter_forbidden/src/filter_forbidden.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | def filter_forbidden(string : str, forbidden : str): 3 | filtered = [letter for letter in string if letter not in forbidden] 4 | return ''.join(filtered) 5 | 6 | if __name__ == "__main__": 7 | sentence = "Once! upon, a time: there was a python!??!?!" 8 | filtered = filter_forbidden(sentence, "!?:,.") 9 | print(filtered) -------------------------------------------------------------------------------- /part11/part11-08_filter_forbidden/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-08_filter_forbidden/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-08_filter_forbidden/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-08_filter_forbidden/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-09_products_in_shopping_list/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-09_products_in_shopping_list/src/products_in_shopping_list.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class ShoppingList: 3 | def __init__(self): 4 | self.products = [] 5 | 6 | def number_of_items(self): 7 | return len(self.products) 8 | 9 | def add(self, product: str, number: int): 10 | self.products.append((product, number)) 11 | 12 | def __iter__(self): 13 | self.n = 0 14 | return self 15 | 16 | def __next__(self): 17 | if self.n < len(self.products): 18 | product = self.products[self.n] 19 | self.n += 1 20 | return product 21 | else: 22 | raise StopIteration 23 | 24 | def products_in_shopping_list(shopping_list: ShoppingList, amount: int): 25 | return [product[0] for product in shopping_list if product[1]>=amount] 26 | 27 | if __name__ == "__main__": 28 | my_list = ShoppingList() 29 | my_list.add("bananas", 10) 30 | my_list.add("apples", 5) 31 | my_list.add("alcohol free beer", 24) 32 | my_list.add("pineapple", 1) 33 | 34 | print("the shopping list contains at least 8 of the following items:") 35 | for product in products_in_shopping_list(my_list, 8): 36 | print(product) -------------------------------------------------------------------------------- /part11/part11-09_products_in_shopping_list/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-09_products_in_shopping_list/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-09_products_in_shopping_list/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-09_products_in_shopping_list/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-10_cheaper_properties/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-10_cheaper_properties/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-10_cheaper_properties/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-10_cheaper_properties/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-10_cheaper_properties/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-11_lengths_of_strings/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-11_lengths_of_strings/src/lengths_of_strings.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | def lengths(strings: list): 3 | return {word : len(word) for word in strings } 4 | 5 | if __name__ == "__main__": 6 | word_list = ["once", "upon" , "a", "time", "in"] 7 | 8 | word_lengths = lengths(word_list) 9 | print(word_lengths) -------------------------------------------------------------------------------- /part11/part11-11_lengths_of_strings/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-11_lengths_of_strings/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-11_lengths_of_strings/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-11_lengths_of_strings/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/comprehensions.txt: -------------------------------------------------------------------------------- 1 | List comprehension is an elegant way to define and create lists based on existing lists. 2 | List comprehension is generally more compact and faster than normal functions and loops for creating list. 3 | However, we should avoid writing very long list comprehensions in one line to ensure that code is user-friendly. 4 | Remember, every list comprehension can be rewritten in for loop, but every for loop can’t be rewritten in the form of list comprehension. -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/programming.txt: -------------------------------------------------------------------------------- 1 | Programming is designing and implementing software. The functionality is implemented based on the wishes and requirements of the users and the customers. Programs are typically implemented (i.e., written or "coded") in a programming language meant to be written and read by humans. 2 | 3 | There are hundreds of programming languages out there, and this course focuses one of them. The language used in this course is Java, which is one of the most commonly-used programming languages in the world. Learning Java also makes it easier to pick up other programming languages. 4 | 5 | Programming languages, such as Java, have many commands built-in that a programmer uses when developing software. This makes programming easier as you don't need to implement everything from scratch. For example, programming languages typically have built-in options available for different menus and views used for making graphical user interfaces. Indeed, a large part of programming is making use of available functions and tools in solving problems — this, however, requires programming experience, which you only gain by programming. -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/src/comprehensions.txt: -------------------------------------------------------------------------------- 1 | List comprehension is an elegant way to define and create lists based on existing lists. 2 | List comprehension is generally more compact and faster than normal functions and loops for creating list. 3 | However, we should avoid writing very long list comprehensions in one line to ensure that code is user-friendly. 4 | Remember, every list comprehension can be rewritten in for loop, but every for loop can’t be rewritten in the form of list comprehension. -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/src/most_common_words.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | import string 3 | 4 | def strip_special_chars(word: string): 5 | final_word = '' 6 | for character in word: 7 | if character not in string.punctuation: 8 | final_word += character 9 | return final_word 10 | 11 | def most_common_words(filename: str, lower_limit: int): 12 | with open(filename) as file: 13 | all_words = [] 14 | for line in file: 15 | words = line.strip().split(' ') 16 | for word in words: 17 | all_words.append(strip_special_chars(word)) 18 | word_count = {word : all_words.count(word) for word in all_words} 19 | return {word: count for word, count in word_count.items() if count >= lower_limit} -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/src/programming.txt: -------------------------------------------------------------------------------- 1 | Programming is designing and implementing software. The functionality is implemented based on the wishes and requirements of the users and the customers. Programs are typically implemented (i.e., written or "coded") in a programming language meant to be written and read by humans. 2 | 3 | There are hundreds of programming languages out there, and this course focuses one of them. The language used in this course is Java, which is one of the most commonly-used programming languages in the world. Learning Java also makes it easier to pick up other programming languages. 4 | 5 | Programming languages, such as Java, have many commands built-in that a programmer uses when developing software. This makes programming easier as you don't need to implement everything from scratch. For example, programming languages typically have built-in options available for different menus and views used for making graphical user interfaces. Indeed, a large part of programming is making use of available functions and tools in solving problems — this, however, requires programming experience, which you only gain by programming. -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-12_most_common_words/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-12_most_common_words/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-13_add_numbers_to_list/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-13_add_numbers_to_list/src/add_numbers_to_list.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | def add_numbers_to_list(numbers: list): 3 | if len(numbers) % 5 != 0: 4 | numbers.append(numbers[-1]+1) 5 | add_numbers_to_list(numbers) 6 | 7 | if __name__ == "__main__": 8 | numbers = [1,3,4,5,10,11] 9 | add_numbers_to_list(numbers) 10 | print(numbers) -------------------------------------------------------------------------------- /part11/part11-13_add_numbers_to_list/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-13_add_numbers_to_list/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-13_add_numbers_to_list/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-13_add_numbers_to_list/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-14_recursive_sum/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-14_recursive_sum/src/recursive_sum.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | 3 | def recursive_sum(number: int): 4 | # if the number is 1, there is nothing else to add 5 | if number <= 1: 6 | return number 7 | 8 | # fill in the rest of the function 9 | else: 10 | return number + recursive_sum(number-1) 11 | 12 | if __name__ == "__main__": 13 | result = recursive_sum(3) 14 | print(result) 15 | 16 | print(recursive_sum(5)) 17 | print(recursive_sum(10)) -------------------------------------------------------------------------------- /part11/part11-14_recursive_sum/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-14_recursive_sum/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-14_recursive_sum/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-14_recursive_sum/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-15_balanced_brackets/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-15_balanced_brackets/src/balanced_brackets.py: -------------------------------------------------------------------------------- 1 | def balanced_brackets(my_string: str): 2 | my_string = ''.join([character for character in my_string if character in '()[]']) 3 | 4 | if len(my_string) == 0: 5 | return True 6 | 7 | if not (my_string[0] == '(' and my_string[-1] == ')') and not (my_string[0] == '[' and my_string[-1] == ']'): 8 | return False 9 | 10 | # remove first and last character 11 | return balanced_brackets(my_string[1:-1]) 12 | 13 | if __name__ == "__main__": 14 | ok = balanced_brackets("(((())))") 15 | print(ok) 16 | 17 | # there is one closing bracket too many, so this produces False 18 | ok = balanced_brackets("()())") 19 | print(ok) 20 | 21 | # this one starts with a closing bracket, False again 22 | ok = balanced_brackets(")()") 23 | print(ok) 24 | 25 | # this produces False because the function only handles entirely nested brackets 26 | ok = balanced_brackets("()(())") 27 | print(ok) -------------------------------------------------------------------------------- /part11/part11-15_balanced_brackets/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-15_balanced_brackets/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-15_balanced_brackets/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-15_balanced_brackets/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-16_greatest_node/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-16_greatest_node/src/greatest_node.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class Node: 3 | """ Class is modeling single node in binary tree """ 4 | def __init__(self, value, left_child:'Node' = None, right_child:'Node' = None): 5 | self.value = value 6 | self.left_child = left_child 7 | self.right_child = right_child 8 | 9 | def greatest_node(root: Node): 10 | greatest = root.value 11 | 12 | if root.left_child is not None: 13 | left = greatest_node(root.left_child) 14 | if left > greatest: 15 | greatest = left 16 | if root.right_child is not None: 17 | right = greatest_node(root.right_child) 18 | if right > greatest: 19 | greatest = right 20 | 21 | return greatest 22 | 23 | 24 | if __name__ == "__main__": 25 | tree = Node(2) 26 | 27 | tree.left_child = Node(3) 28 | tree.left_child.left_child = Node(5) 29 | tree.left_child.right_child = Node(8) 30 | 31 | tree.right_child = Node(4) 32 | tree.right_child.right_child = Node(11) 33 | 34 | print(greatest_node(tree)) -------------------------------------------------------------------------------- /part11/part11-16_greatest_node/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-16_greatest_node/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-16_greatest_node/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-16_greatest_node/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-17_bosses_and_subordinates/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-17_bosses_and_subordinates/src/bosses_and_subordinates.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | class Employee: 3 | def __init__(self, name: str): 4 | self.name = name 5 | self.subordinates = [] 6 | 7 | def add_subordinate(self, employee: 'Employee'): 8 | self.subordinates.append(employee) 9 | 10 | def count_subordinates(employee: Employee): 11 | sub = 0 12 | for emp in employee.subordinates: 13 | sub += 1 14 | sub += count_subordinates(emp) 15 | return sub 16 | 17 | if __name__ == "__main__": 18 | if __name__ == "__main__": 19 | t1 = Employee("Sally") 20 | t2 = Employee("Eric") 21 | t3 = Employee("Matthew") 22 | t4 = Employee("Emily") 23 | t5 = Employee("Adele") 24 | t6 = Employee("Claire") 25 | t1.add_subordinate(t4) 26 | t1.add_subordinate(t6) 27 | t4.add_subordinate(t2) 28 | t4.add_subordinate(t3) 29 | t4.add_subordinate(t5) 30 | print(count_subordinates(t1)) 31 | print(count_subordinates(t4)) 32 | print(count_subordinates(t5)) -------------------------------------------------------------------------------- /part11/part11-17_bosses_and_subordinates/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-17_bosses_and_subordinates/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-17_bosses_and_subordinates/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-17_bosses_and_subordinates/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-18_order_book/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-18_order_book/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-18_order_book/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-18_order_book/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-18_order_book/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part11/part11-19_order_book_application/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part11/part11-19_order_book_application/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part11/part11-19_order_book_application/test/__init__.py -------------------------------------------------------------------------------- /part11/part11-19_order_book_application/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part11/part11-19_order_book_application/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-01_remaining_stock/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-01_remaining_stock/src/remaining_stock.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | def sort_by_remaining_stock(items: list): 3 | def order_by_stock(item): 4 | return item[2] 5 | return sorted(items, key=order_by_stock) 6 | 7 | if __name__ == '__main__': 8 | products = [("banana", 5.95, 12), ("apple", 3.95, 3), ("orange", 4.50, 2), ("watermelon", 4.95, 22)] 9 | 10 | for product in sort_by_remaining_stock(products): 11 | print(f"{product[0]} {product[2]} pcs") -------------------------------------------------------------------------------- /part12/part12-01_remaining_stock/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-01_remaining_stock/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-01_remaining_stock/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-01_remaining_stock/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-02_seasons/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-02_seasons/src/seasons.py: -------------------------------------------------------------------------------- 1 | # Write your solution here: 2 | import re 3 | 4 | 5 | def sort_by_seasons(shows : list): 6 | def order_by_seasons(show : dict): 7 | return show['seasons'] 8 | return sorted(shows, key = order_by_seasons) 9 | 10 | if __name__ == "__main__": 11 | shows = [{ "name": "Dexter", "rating" : 8.6, "seasons":9 }, { "name": "Friends", "rating" : 8.9, "seasons":10 }, { "name": "Simpsons", "rating" : 8.7, "seasons":32 } ] 12 | 13 | for show in sort_by_seasons(shows): 14 | print(f"{show['name']} {show['seasons']} seasons") -------------------------------------------------------------------------------- /part12/part12-02_seasons/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-02_seasons/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-02_seasons/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-02_seasons/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-02_seasons/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part12/part12-03_ratings/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-03_ratings/src/ratings.py: -------------------------------------------------------------------------------- 1 | # TEE RATKAISUSI TÄHÄN: 2 | def sort_by_ratings(items: list): 3 | def order_by_ratings(item: dict): 4 | return item['rating'] 5 | return sorted(items, key=order_by_ratings, reverse=True) 6 | 7 | if __name__ == "__main__": 8 | shows = [{ "name": "Dexter", "rating" : 8.6, "seasons":9 }, { "name": "Friends", "rating" : 8.9, "seasons":10 }, { "name": "Simpsons", "rating" : 8.7, "seasons":32 } ] 9 | 10 | print("Rating according to IMDB") 11 | for show in sort_by_ratings(shows): 12 | print(f"{show['name']} {show['rating']}") -------------------------------------------------------------------------------- /part12/part12-03_ratings/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-03_ratings/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-03_ratings/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-03_ratings/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-03_ratings/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part12/part12-04_climbing_route/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-04_climbing_route/src/climbing_route.py: -------------------------------------------------------------------------------- 1 | class ClimbingRoute: 2 | def __init__(self, name: str, length: int, grade: str): 3 | self.name = name 4 | self.length = length 5 | self.grade = grade 6 | 7 | def __str__(self): 8 | return f"{self.name}, length {self.length} metres, grade {self.grade}" 9 | 10 | # Write your solution herer: 11 | def order_by_length(route: ClimbingRoute): 12 | return route.length 13 | 14 | def sort_by_length(routes: list): 15 | return sorted(routes, key=order_by_length, reverse=True) 16 | 17 | def sort_by_difficulty(routes: list): 18 | def order_by_difficulty(route: ClimbingRoute): 19 | return [route.grade, route.length] 20 | return sorted(routes, key=order_by_difficulty, reverse=True) 21 | 22 | if __name__ == '__main__': 23 | r1 = ClimbingRoute("Edge", 38, "6A+") 24 | r2 = ClimbingRoute("Smooth operator", 11, "7A") 25 | r3 = ClimbingRoute("Synchro", 14, "8C+") 26 | r4 = ClimbingRoute("Small steps", 12, "6A+") 27 | 28 | routes = [r1, r2, r3, r4] 29 | for route in sort_by_difficulty(routes): 30 | print(route) 31 | -------------------------------------------------------------------------------- /part12/part12-04_climbing_route/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-04_climbing_route/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-04_climbing_route/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-04_climbing_route/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-05_climbing_areas/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-05_climbing_areas/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-05_climbing_areas/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-05_climbing_areas/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-05_climbing_areas/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-06_ballplayers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-06_ballplayers/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-06_ballplayers/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-06_ballplayers/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-06_ballplayers/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-07_product_search/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-07_product_search/src/product_search.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | def search(products: list, criterion: callable): 3 | return [product for product in products if criterion(product)] -------------------------------------------------------------------------------- /part12/part12-07_product_search/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-07_product_search/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-07_product_search/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-07_product_search/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-08_even_numbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-08_even_numbers/src/even_numbers.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | def even_numbers(beginning: int, maximum: int): 3 | number = beginning 4 | # return [a for a in range(beginning,maximum+1) if a%2==0] 5 | while number <= maximum: 6 | if number%2 == 0: 7 | yield number 8 | number += 1 9 | 10 | if __name__=='__main_': 11 | numbers = even_numbers(2, 10) 12 | print(numbers) 13 | for number in numbers: 14 | print(number) -------------------------------------------------------------------------------- /part12/part12-08_even_numbers/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-08_even_numbers/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-08_even_numbers/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-08_even_numbers/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-09_prime_numbers/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-09_prime_numbers/src/prime_numbers.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | def prime_numbers(): 3 | number = 2 4 | while True: 5 | for a in range(2,number): 6 | if number % a ==0: 7 | break 8 | else: 9 | yield number 10 | number += 1 11 | 12 | 13 | while True: 14 | if number%number==0: 15 | yield number 16 | number += 1 17 | 18 | if __name__=='__main_': 19 | numbers = prime_numbers() 20 | for i in range(8): 21 | print(next(numbers)) -------------------------------------------------------------------------------- /part12/part12-09_prime_numbers/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-09_prime_numbers/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-09_prime_numbers/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-09_prime_numbers/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-10_random_words/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-10_random_words/src/random_words.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | def word_generator(letters: str, length: int, amount:int): 4 | return ("".join([choice(letters ) for i in range(length)]) for j in range(amount)) 5 | 6 | if __name__ == "__main__": 7 | wordgen = word_generator("abcdefg", 3, 5) 8 | for word in wordgen: 9 | print(word) -------------------------------------------------------------------------------- /part12/part12-10_random_words/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-10_random_words/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-10_random_words/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-10_random_words/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-11_attempted_courses/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-11_attempted_courses/src/attempted_courses.py: -------------------------------------------------------------------------------- 1 | class CourseAttempt: 2 | def __init__(self, student_name: str, course_name: str, grade: int): 3 | self.student_name = student_name 4 | self.course_name = course_name 5 | self.grade = grade 6 | 7 | def __str__(self): 8 | return f"{self.student_name}, grade for the course {self.course_name} {self.grade}" 9 | 10 | # Write your solution here 11 | 12 | def names_of_students(attempts: list): 13 | return list(map(lambda t: t.student_name,attempts)) 14 | 15 | def course_names(attempts: list): 16 | return sorted(set(list(map(lambda t: t.course_name,attempts)))) 17 | if __name__=='__main__': 18 | s1 = CourseAttempt("Peter Python", "Introduction to Programming", 3) 19 | s2 = CourseAttempt("Olivia C. Objective", "Introduction to Programming", 5) 20 | s3 = CourseAttempt("Peter Python", "Advanced Course in Programming", 2) 21 | 22 | for name in course_names([s1, s2, s3]): 23 | print(name) -------------------------------------------------------------------------------- /part12/part12-11_attempted_courses/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-11_attempted_courses/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-11_attempted_courses/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-11_attempted_courses/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-12_filtering_attempts/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-12_filtering_attempts/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-12_filtering_attempts/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-12_filtering_attempts/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-12_filtering_attempts/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-13_credits/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-13_credits/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-13_credits/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-13_credits/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-13_credits/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-13_credits/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part12/part12-14_regular_expressions/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-14_regular_expressions/src/regular_expressions.py: -------------------------------------------------------------------------------- 1 | # Write your solution here 2 | import re 3 | 4 | def is_dotw(my_string: str): 5 | if re.search("Mon|Tue|Wed|Thu|Fri|Sat|Sun", my_string): 6 | return True 7 | else: 8 | return False 9 | 10 | def all_vowels(my_string: str): 11 | for a in my_string: 12 | if re.search("[aeiouAEIOU]", a): 13 | continue 14 | else: 15 | return False 16 | return True 17 | 18 | def time_of_day(my_string: str): 19 | if re.search("^([0-1][0-9]|[2][0-4]):[0-5][0-9]:[0-5][0-9]$", my_string): 20 | return True 21 | else: 22 | return False 23 | 24 | if __name__=='__main__': 25 | print(time_of_day("12:43:01")) 26 | print(time_of_day("AB:01:CD")) 27 | print(time_of_day("17:59:59")) 28 | print(time_of_day("33:66:77")) 29 | -------------------------------------------------------------------------------- /part12/part12-14_regular_expressions/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-14_regular_expressions/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-14_regular_expressions/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-14_regular_expressions/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part12/part12-15_hockey_statistics/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part12/part12-15_hockey_statistics/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part12/part12-15_hockey_statistics/test/__init__.py -------------------------------------------------------------------------------- /part12/part12-15_hockey_statistics/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part12/part12-15_hockey_statistics/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-01_four_robots/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-01_four_robots/src/main.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | 3 | pygame.init() 4 | width_window = 640 5 | height_window = 480 6 | 7 | window = pygame.display.set_mode((width_window, height_window)) 8 | 9 | robot = pygame.image.load("robot.png") 10 | 11 | width = robot.get_width() 12 | height = robot.get_height() 13 | 14 | window.fill((0,0,0)) 15 | 16 | window.blit(robot, (0,0)) 17 | window.blit(robot, (width_window-width,0)) 18 | window.blit(robot, (0,height_window-height)) 19 | window.blit(robot, (width_window-width,height_window-height)) 20 | pygame.display.flip() 21 | 22 | while True: 23 | for event in pygame.event.get(): 24 | if event.type == pygame.QUIT: 25 | exit() -------------------------------------------------------------------------------- /part13/part13-01_four_robots/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-01_four_robots/src/robot.png -------------------------------------------------------------------------------- /part13/part13-01_four_robots/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-01_four_robots/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-01_four_robots/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.four_robots') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-01_four_robots/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-01_four_robots/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-02_robots_row/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-02_robots_row/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-02_robots_row/robot.png -------------------------------------------------------------------------------- /part13/part13-02_robots_row/src/main.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | import pygame 3 | 4 | pygame.init() 5 | 6 | window_width = 640 7 | window_height = 480 8 | 9 | window = pygame.display.set_mode((window_width, window_height)) 10 | robot = pygame.image.load("robot.png") 11 | 12 | width = robot.get_width() 13 | 14 | window.fill((0,0,0)) 15 | 16 | for i in range(0,10): 17 | window.blit(robot,(75+width*i,100)) 18 | pygame.display.flip() 19 | 20 | while True: 21 | for event in pygame.event.get(): 22 | if event.type == pygame.QUIT: 23 | exit() -------------------------------------------------------------------------------- /part13/part13-02_robots_row/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-02_robots_row/src/robot.png -------------------------------------------------------------------------------- /part13/part13-02_robots_row/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-02_robots_row/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-02_robots_row/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.robots_row') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-02_robots_row/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-02_robots_row/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-03_hundred_robots/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-03_hundred_robots/src/main.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | import pygame 3 | 4 | pygame.init() 5 | 6 | window_width = 640 7 | window_height = 480 8 | 9 | window = pygame.display.set_mode((window_width, window_height)) 10 | robot = pygame.image.load("robot.png") 11 | 12 | width = robot.get_width() 13 | height = robot.get_height() 14 | 15 | window.fill((0,0,0)) 16 | 17 | for i in range(10): 18 | for j in range(10): 19 | window.blit(robot, (75+10*i+40*j, 100+i*20)) 20 | pygame.display.flip() 21 | 22 | while True: 23 | for event in pygame.event.get(): 24 | if event.type == pygame.QUIT: 25 | exit() 26 | -------------------------------------------------------------------------------- /part13/part13-03_hundred_robots/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-03_hundred_robots/src/robot.png -------------------------------------------------------------------------------- /part13/part13-03_hundred_robots/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-03_hundred_robots/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-03_hundred_robots/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.hundred_robots') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-03_hundred_robots/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-03_hundred_robots/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-04_random_robots/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-04_random_robots/src/main.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | from random import randint 3 | import pygame 4 | 5 | pygame.init() 6 | 7 | window_width = 640 8 | window_height = 480 9 | 10 | window = pygame.display.set_mode((window_width , window_height)) 11 | robot = pygame.image.load("robot.png") 12 | 13 | width = robot.get_width() 14 | height = robot.get_height() 15 | 16 | window.fill((0, 0, 0)) 17 | 18 | for i in range(1000): 19 | x = randint(0, window_width-width) 20 | y = randint(0, window_height-height) 21 | window.blit(robot, (x, y)) 22 | 23 | pygame.display.flip() 24 | 25 | while True: 26 | for event in pygame.event.get(): 27 | if event.type == pygame.QUIT: 28 | exit() -------------------------------------------------------------------------------- /part13/part13-04_random_robots/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-04_random_robots/src/robot.png -------------------------------------------------------------------------------- /part13/part13-04_random_robots/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-04_random_robots/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-04_random_robots/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.random_robots') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-04_random_robots/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-04_random_robots/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-05_vertical_movement/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-05_vertical_movement/src/main.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | import pygame 3 | 4 | pygame.init() 5 | 6 | window_width = 640 7 | window_height = 480 8 | 9 | window = pygame.display.set_mode((window_width, window_height)) 10 | robot = pygame.image.load("robot.png") 11 | 12 | x = 0 13 | y = 0 14 | velocity = 1 15 | clock = pygame.time.Clock() 16 | 17 | while True: 18 | for event in pygame.event.get(): 19 | if event.type == pygame.QUIT: 20 | exit() 21 | 22 | window.fill((0, 0, 0)) 23 | window.blit(robot, (x, y)) 24 | pygame.display.flip() 25 | 26 | y += velocity 27 | if velocity > 0 and y+robot.get_height() >= 480: 28 | velocity = -velocity 29 | if velocity < 0 and y <= 0: 30 | velocity = -velocity 31 | 32 | clock.tick(60) -------------------------------------------------------------------------------- /part13/part13-05_vertical_movement/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-05_vertical_movement/src/robot.png -------------------------------------------------------------------------------- /part13/part13-05_vertical_movement/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-05_vertical_movement/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-05_vertical_movement/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.vertical_movement') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-05_vertical_movement/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-05_vertical_movement/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-06_round_the_perimeter/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-06_round_the_perimeter/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-06_round_the_perimeter/src/robot.png -------------------------------------------------------------------------------- /part13/part13-06_round_the_perimeter/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-06_round_the_perimeter/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-06_round_the_perimeter/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.round_the_perimeter') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-06_round_the_perimeter/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-06_round_the_perimeter/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-07_two_robots/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-07_two_robots/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-07_two_robots/src/robot.png -------------------------------------------------------------------------------- /part13/part13-07_two_robots/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-07_two_robots/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-07_two_robots/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.two_robots') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-07_two_robots/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-07_two_robots/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-08_robot_circle/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-08_robot_circle/src/main.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | import math 3 | 4 | pygame.init() 5 | 6 | window_width, window_height = 640, 480 7 | 8 | window = pygame.display.set_mode((window_width, window_height)) 9 | robot = pygame.image.load("robot.png") 10 | 11 | width = robot.get_width() 12 | height = robot.get_height() 13 | 14 | angle = 0 15 | radius = 150 16 | number = 10 17 | clock = pygame.time.Clock() 18 | 19 | while True: 20 | for event in pygame.event.get(): 21 | if event.type == pygame.QUIT: 22 | exit() 23 | 24 | window.fill((0, 0, 0)) 25 | for i in range(number): 26 | x = window_width/2+math.cos(angle+2*math.pi*i/number)*radius-width/2 27 | y = window_height/2+math.sin(angle+2*math.pi*i/number)*radius-height/2 28 | window.blit(robot, (x, y)) 29 | pygame.display.flip() 30 | 31 | angle += 0.01 32 | clock.tick(60) -------------------------------------------------------------------------------- /part13/part13-08_robot_circle/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-08_robot_circle/src/robot.png -------------------------------------------------------------------------------- /part13/part13-08_robot_circle/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-08_robot_circle/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-08_robot_circle/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.robot_circle') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-08_robot_circle/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-08_robot_circle/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-09_bouncing_ball/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-09_bouncing_ball/src/ball.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-09_bouncing_ball/src/ball.png -------------------------------------------------------------------------------- /part13/part13-09_bouncing_ball/src/main.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | import pygame 3 | import math 4 | 5 | pygame.init() 6 | 7 | window_width, window_height = 640, 480 8 | 9 | window = pygame.display.set_mode((window_width, window_height)) 10 | ball = pygame.image.load("ball.png") 11 | 12 | width = ball.get_width() 13 | height = ball.get_height() 14 | 15 | h = 1 16 | x = 320 17 | y = 240 18 | 19 | xvelocity = 2 20 | yvelocity = 2 21 | clock = pygame.time.Clock() 22 | 23 | while True: 24 | for event in pygame.event.get(): 25 | if event.type == pygame.QUIT: 26 | exit() 27 | 28 | window.fill((0, 0, 0)) 29 | window.blit(ball, (x, y)) 30 | pygame.display.flip() 31 | 32 | if x+width >= 640 or x <= 0: 33 | xvelocity = -xvelocity 34 | if y+height >= 480 or y <= 0: 35 | yvelocity = -yvelocity 36 | 37 | x += xvelocity 38 | y += yvelocity 39 | 40 | clock.tick(60) -------------------------------------------------------------------------------- /part13/part13-09_bouncing_ball/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-09_bouncing_ball/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-09_bouncing_ball/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.bouncing_ball') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-09_bouncing_ball/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-09_bouncing_ball/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-10_robot_invasion/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-10_robot_invasion/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-10_robot_invasion/src/robot.png -------------------------------------------------------------------------------- /part13/part13-10_robot_invasion/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-10_robot_invasion/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-10_robot_invasion/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.robot_invasion') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-10_robot_invasion/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-10_robot_invasion/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-11_four_directions/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-11_four_directions/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-11_four_directions/src/robot.png -------------------------------------------------------------------------------- /part13/part13-11_four_directions/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-11_four_directions/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-11_four_directions/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.four_directions') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-11_four_directions/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-11_four_directions/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-12_four_walls/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-12_four_walls/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-12_four_walls/src/robot.png -------------------------------------------------------------------------------- /part13/part13-12_four_walls/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-12_four_walls/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-12_four_walls/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.four_walls') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-12_four_walls/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-12_four_walls/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-13_two_players/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-13_two_players/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-13_two_players/src/robot.png -------------------------------------------------------------------------------- /part13/part13-13_two_players/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-13_two_players/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-13_two_players/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.two_players') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-13_two_players/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-13_two_players/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-14_robot_and_mouse/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-14_robot_and_mouse/src/main.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | import pygame 3 | 4 | pygame.init() 5 | 6 | window_width, window_height = 640, 480 7 | 8 | window = pygame.display.set_mode((window_width, window_height)) 9 | robot = pygame.image.load("robot.png") 10 | 11 | width = robot.get_width() 12 | height = robot.get_height() 13 | 14 | robot_x = 0 15 | robot_y = 0 16 | 17 | clock = pygame.time.Clock() 18 | 19 | while True: 20 | for event in pygame.event.get(): 21 | if event.type == pygame.MOUSEMOTION: 22 | robot_x = event.pos[0]-width/2 23 | robot_y = event.pos[1]-height/2 24 | 25 | if event.type == pygame.QUIT: 26 | exit(0) 27 | 28 | window.fill((0, 0, 0)) 29 | window.blit(robot, (robot_x, robot_y)) 30 | pygame.display.flip() 31 | 32 | clock.tick(60) -------------------------------------------------------------------------------- /part13/part13-14_robot_and_mouse/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-14_robot_and_mouse/src/robot.png -------------------------------------------------------------------------------- /part13/part13-14_robot_and_mouse/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-14_robot_and_mouse/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-14_robot_and_mouse/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.robot_and_mouse') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-14_robot_and_mouse/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-14_robot_and_mouse/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-15_robot_location/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-15_robot_location/src/main.py: -------------------------------------------------------------------------------- 1 | # WRITE YOUR SOLUTION HERE: 2 | from random import randint 3 | import pygame 4 | 5 | pygame.init() 6 | 7 | window_width, window_height = 640, 480 8 | 9 | window = pygame.display.set_mode((window_width, window_height)) 10 | robot = pygame.image.load("robot.png") 11 | 12 | width = robot.get_width() 13 | height = robot.get_height() 14 | 15 | robot_x = 0 16 | robot_y = 0 17 | target_x = 0 18 | target_y = 0 19 | 20 | clock = pygame.time.Clock() 21 | 22 | while True: 23 | for event in pygame.event.get(): 24 | if event.type == pygame.MOUSEBUTTONDOWN: 25 | target_x = event.pos[0] 26 | target_y = event.pos[1] 27 | 28 | if target_x > robot_x and target_x < robot_x+robot.get_width() and target_y > robot_y and target_x < robot_x+robot.get_width(): 29 | robot_x = randint(0,640-robot.get_width()) 30 | robot_y = randint(0,480-robot.get_height()) 31 | 32 | window.fill((0, 0, 0)) 33 | window.blit(robot, (robot_x, robot_y)) 34 | pygame.display.flip() 35 | 36 | if event.type == pygame.QUIT: 37 | exit() -------------------------------------------------------------------------------- /part13/part13-15_robot_location/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-15_robot_location/src/robot.png -------------------------------------------------------------------------------- /part13/part13-15_robot_location/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-15_robot_location/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-15_robot_location/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.robot_location') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-15_robot_location/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-15_robot_location/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-16_clock/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-16_clock/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-16_clock/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-16_clock/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.clock') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-16_clock/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-16_clock/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | -------------------------------------------------------------------------------- /part13/part13-16_clock/tmc/runner.py: -------------------------------------------------------------------------------- 1 | from unittest import TextTestRunner, TestLoader 2 | from .result import TMCResult 3 | from .points import _parse_points, _name_test 4 | from itertools import chain 5 | import json 6 | 7 | 8 | class TMCTestRunner(TextTestRunner): 9 | """A test runner for TMC exercises. 10 | """ 11 | 12 | resultclass = TMCResult 13 | 14 | def __init__(self, *args, **kwargs): 15 | super(TMCTestRunner, self).__init__(*args, **kwargs) 16 | 17 | def run(self, test): 18 | print('Running tests with some TMC magic...') 19 | return super(TMCTestRunner, self).run(test) 20 | 21 | def available_points(self): 22 | testLoader = TestLoader() 23 | tests = testLoader.discover('.', 'test*.py', None) 24 | try: 25 | tests = list(chain(*chain(*tests._tests))) 26 | except Exception as error: 27 | print("Received following Exception:", error) 28 | tests.debug() 29 | 30 | points = map(_parse_points, tests) 31 | names = map(_name_test, tests) 32 | 33 | result = dict(zip(names, points)) 34 | 35 | with open('.available_points.json', 'w') as f: 36 | json.dump(result, f, ensure_ascii=False) 37 | -------------------------------------------------------------------------------- /part13/part13-17_asteroids/.tmcproject.yml: -------------------------------------------------------------------------------- 1 | --- 2 | tests_timeout_ms: 10000 3 | sandbox_image: eu.gcr.io/moocfi-public/tmc-sandbox-python 4 | -------------------------------------------------------------------------------- /part13/part13-17_asteroids/src/robot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-17_asteroids/src/robot.png -------------------------------------------------------------------------------- /part13/part13-17_asteroids/src/rock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-17_asteroids/src/rock.png -------------------------------------------------------------------------------- /part13/part13-17_asteroids/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/P4r1nc3/Python_Programming_MOOC_2025_II/b5dba3709eeb3b5ea546ca00a554e73de21d9ae1/part13/part13-17_asteroids/test/__init__.py -------------------------------------------------------------------------------- /part13/part13-17_asteroids/test/test_main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch 3 | 4 | from tmc import points, reflect 5 | from tmc.utils import load, load_module, reload_module, get_stdout, check_source 6 | 7 | @points('13.asteroids') 8 | class Part13Test(unittest.TestCase): 9 | def test_1_pygame(self): 10 | pass 11 | 12 | if __name__ == '__main__': 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /part13/part13-17_asteroids/tmc/__init__.py: -------------------------------------------------------------------------------- 1 | from .points import points 2 | from .runner import TMCTestRunner 3 | -------------------------------------------------------------------------------- /part13/part13-17_asteroids/tmc/django.py: -------------------------------------------------------------------------------- 1 | from django.test.runner import DiscoverRunner 2 | from tmc import runner 3 | 4 | 5 | class TMCDiscoverRunner(DiscoverRunner): 6 | test_runner = runner.TMCTestRunner 7 | --------------------------------------------------------------------------------