├── src ├── lecture │ ├── __init__.py │ ├── examples │ │ ├── __init__.py │ │ ├── ex29_modules │ │ │ ├── __init__.py │ │ │ └── rational │ │ │ │ ├── __init__.py │ │ │ │ ├── rational_list.py │ │ │ │ └── rational_dict.py │ │ ├── ex30_modular_calc │ │ │ ├── __init__.py │ │ │ ├── ui │ │ │ │ └── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ └── rational.py │ │ │ └── rational_calc.py │ │ ├── ex36_rational_calc │ │ │ ├── __init__.py │ │ │ ├── calculator.py │ │ │ └── test_calculator.py │ │ ├── ex25_function_call_visualisation.py │ │ ├── ex10_exponential_search.py │ │ ├── ex26_parameter_passing.py │ │ ├── ex08_sequential_search.py │ │ ├── ex27_side_effects.py │ │ ├── ex01_basic_syntax.py │ │ ├── ex14_merge_sort.py │ │ ├── ex03_program_flow.py │ │ ├── ex12_stable_sort.py │ │ ├── ex35_instance_vs_class_fields.py │ │ ├── ex02_basic_compound_types.py │ │ ├── ex32_python_class_particularities.py │ │ ├── ex42_tdd_1.py │ │ ├── ex11_search_comparison.py │ │ ├── ex20_longest_increasing_subsequence.py │ │ ├── ex31_exceptions.py │ │ ├── ex40_black_box_white_box.py │ │ ├── ex09_binary_search.py │ │ ├── ex13_insertion_sort.py │ │ └── ex38_pickle_files.py │ └── livecoding │ │ ├── __init__.py │ │ ├── lecture_12 │ │ └── __init__.py │ │ ├── lecture_13 │ │ └── __init__.py │ │ ├── lecture_7 │ │ ├── __init__.py │ │ ├── rational_as_list.py │ │ ├── rational_as_dict.py │ │ └── calc.py │ │ ├── lecture_8 │ │ ├── __init__.py │ │ └── calc.py │ │ ├── lecture_9 │ │ ├── __init__.py │ │ ├── ui │ │ │ ├── __init__.py │ │ │ └── ui.py │ │ ├── domain │ │ │ ├── __init__.py │ │ │ ├── bakery_product.py │ │ │ ├── ingredient.py │ │ │ ├── bakery_object.py │ │ │ └── recipe.py │ │ ├── repo │ │ │ └── __init__.py │ │ ├── services │ │ │ ├── __init__.py │ │ │ └── services.py │ │ ├── test │ │ │ ├── __init__.py │ │ │ ├── test_ingredient.py │ │ │ └── test_memory_repo.py │ │ ├── recipes.txt │ │ ├── settings.properties │ │ └── ingredients.txt │ │ └── lecture_2.py ├── seminar │ ├── __init__.py │ ├── group911 │ │ └── __init__.py │ ├── group912 │ │ └── __init__.py │ ├── group913 │ │ ├── __init__.py │ │ ├── seminar_10 │ │ │ ├── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── client.py │ │ │ │ └── rental.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ ├── car_service.py │ │ │ │ ├── client_service.py │ │ │ │ └── rental_service.py │ │ │ ├── repository │ │ │ │ └── __init__.py │ │ │ └── rentals.txt │ │ ├── seminar_11 │ │ │ ├── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── car_rental_exception.py │ │ │ │ ├── validator_exception.py │ │ │ │ ├── rental.py │ │ │ │ └── client.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ └── car_rental_exception.py │ │ │ ├── repository │ │ │ │ ├── __init__.py │ │ │ │ └── repository_exception.py │ │ │ └── util.py │ │ ├── seminar_13 │ │ │ ├── __init__.py │ │ │ ├── sentinces.txt │ │ │ ├── start.py │ │ │ └── repository.py │ │ ├── seminar_14 │ │ │ ├── __init__.py │ │ │ ├── test_flights.txt │ │ │ ├── start.py │ │ │ ├── flights.txt │ │ │ ├── seminar_14.py │ │ │ ├── tests.py │ │ │ └── repository.py │ │ ├── seminar_8 │ │ │ ├── __init__.py │ │ │ ├── game.py │ │ │ └── ui.py │ │ ├── seminar_9 │ │ │ ├── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ └── car.py │ │ │ └── repository │ │ │ │ └── __init__.py │ │ └── seminar_7 │ │ │ ├── __init__.py │ │ │ ├── game.py │ │ │ └── ui.py │ ├── group914 │ │ ├── __init__.py │ │ ├── seminar_10 │ │ │ ├── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── client.py │ │ │ │ └── rental.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ ├── car_service.py │ │ │ │ ├── client_service.py │ │ │ │ └── rental_service.py │ │ │ ├── repository │ │ │ │ └── __init__.py │ │ │ ├── cars.txt │ │ │ └── rentals.txt │ │ ├── seminar_12 │ │ │ └── __init__.py │ │ ├── seminar_13 │ │ │ ├── __init__.py │ │ │ ├── start.py │ │ │ ├── sentences.txt │ │ │ ├── domain.py │ │ │ ├── services.py │ │ │ └── repository.py │ │ ├── seminar_8 │ │ │ ├── __init__.py │ │ │ ├── ui.py │ │ │ └── game.py │ │ ├── seminar_9 │ │ │ ├── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ └── car.py │ │ │ └── repository │ │ │ │ └── __init__.py │ │ ├── seminar_11 │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── car_rental_exception.py │ │ │ │ ├── validator_exception.py │ │ │ │ ├── rental.py │ │ │ │ └── client.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ ├── car_rental_exception.py │ │ │ │ └── car_service.py │ │ │ ├── repository │ │ │ │ ├── __init__.py │ │ │ │ └── repository_exception.py │ │ │ ├── util.py │ │ │ └── __init__.py │ │ ├── seminar_7 │ │ │ ├── __init__.py │ │ │ ├── test.py │ │ │ ├── game.py │ │ │ └── ui.py │ │ └── seminar_14.py │ ├── group915 │ │ ├── __init__.py │ │ ├── Seminar7 │ │ │ ├── __init__.py │ │ │ ├── game.py │ │ │ └── ui.py │ │ ├── Seminar8 │ │ │ ├── __init__.py │ │ │ └── game.py │ │ ├── Seminar9 │ │ │ ├── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ └── car.py │ │ │ ├── ui │ │ │ │ ├── __init__.py │ │ │ │ ├── cars.pickle │ │ │ │ └── ui.py │ │ │ ├── repository │ │ │ │ ├── __init__.py │ │ │ │ ├── carsRepositoryBinary.py │ │ │ │ └── carsRepositoryInMemory.py │ │ │ └── data │ │ │ │ └── cars.pickle │ │ ├── Seminar14 │ │ │ ├── ui │ │ │ │ └── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── myTime.py │ │ │ │ ├── validator.py │ │ │ │ └── flight.py │ │ │ ├── repository │ │ │ │ └── __init__.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ └── flightService.py │ │ │ ├── main.py │ │ │ └── flights.txt │ │ ├── Seminar10 │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── client.py │ │ │ │ ├── rentalValidator.py │ │ │ │ ├── car.py │ │ │ │ └── rental.py │ │ │ ├── repository │ │ │ │ └── __init__.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ ├── car_service.py │ │ │ │ └── client_service.py │ │ │ ├── clients.txt │ │ │ └── cars.txt │ │ ├── Seminar11 │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── car_rental_exception.py │ │ │ │ ├── validator_exception.py │ │ │ │ ├── rental.py │ │ │ │ └── client.py │ │ │ ├── repository │ │ │ │ ├── __init__.py │ │ │ │ └── repository_exception.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ ├── car_rental_exception.py │ │ │ │ └── undo_service.py │ │ │ └── util.py │ │ └── Seminar12 │ │ │ ├── main.py │ │ │ ├── game.py │ │ │ └── requirements.txt │ ├── group916 │ │ ├── __init__.py │ │ ├── Seminar14 │ │ │ ├── __init__.py │ │ │ ├── ui │ │ │ │ └── __init__.py │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── exceptions.py │ │ │ │ ├── myTime.py │ │ │ │ ├── validator.py │ │ │ │ └── flight.py │ │ │ ├── repository │ │ │ │ ├── __init__.py │ │ │ │ └── memoryRepository.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ └── flightService.py │ │ │ ├── main.py │ │ │ └── flights.txt │ │ ├── Seminar7 │ │ │ ├── __init__.py │ │ │ ├── game.py │ │ │ └── ui.py │ │ ├── Seminar8 │ │ │ ├── __init__.py │ │ │ └── game.py │ │ ├── Seminar9 │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ └── car.py │ │ │ ├── ui │ │ │ │ ├── __init__.py │ │ │ │ ├── cars.pickle │ │ │ │ └── ui.py │ │ │ └── repository │ │ │ │ ├── __init__.py │ │ │ │ ├── carRepositoryBinary.py │ │ │ │ └── carRepositoryInMemory.py │ │ ├── Seminar10 │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── client.py │ │ │ │ ├── rentalValidator.py │ │ │ │ ├── rental.py │ │ │ │ └── car.py │ │ │ ├── repository │ │ │ │ └── __init__.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ ├── client_service.py │ │ │ │ └── car_service.py │ │ │ ├── clients.txt │ │ │ └── cars.txt │ │ ├── Seminar11 │ │ │ ├── domain │ │ │ │ ├── __init__.py │ │ │ │ ├── car_rental_exception.py │ │ │ │ ├── validator_exception.py │ │ │ │ ├── rental.py │ │ │ │ └── client.py │ │ │ ├── repository │ │ │ │ ├── __init__.py │ │ │ │ └── repository_exception.py │ │ │ ├── service │ │ │ │ ├── __init__.py │ │ │ │ ├── car_rental_exception.py │ │ │ │ └── undo_service.py │ │ │ └── util.py │ │ ├── .DS_Store │ │ └── Seminar12 │ │ │ ├── main.py │ │ │ ├── exceptions.py │ │ │ ├── game.py │ │ │ └── requirements.txt │ └── group917 │ │ ├── __init__.py │ │ ├── Seminar7 │ │ ├── __init__.py │ │ ├── game.py │ │ └── ui.py │ │ ├── Seminar8 │ │ ├── __init__.py │ │ └── game.py │ │ ├── Seminar14 │ │ ├── ui │ │ │ └── __init__.py │ │ ├── domain │ │ │ ├── __init__.py │ │ │ ├── exceptions.py │ │ │ ├── myTime.py │ │ │ ├── validator.py │ │ │ └── flight.py │ │ ├── repository │ │ │ ├── __init__.py │ │ │ └── memoryRepository.py │ │ ├── service │ │ │ ├── __init__.py │ │ │ └── flightService.py │ │ ├── main.py │ │ └── flights.txt │ │ ├── Seminar9 │ │ ├── domain │ │ │ ├── __init__.py │ │ │ └── car.py │ │ ├── ui │ │ │ ├── __init__.py │ │ │ ├── cars.pickle │ │ │ └── ui.py │ │ └── repository │ │ │ ├── __init__.py │ │ │ └── carRepositoryBinary.py │ │ ├── Seminar10 │ │ ├── domain │ │ │ ├── __init__.py │ │ │ ├── client.py │ │ │ ├── rentalValidator.py │ │ │ ├── car.py │ │ │ └── rental.py │ │ ├── repository │ │ │ └── __init__.py │ │ ├── service │ │ │ ├── __init__.py │ │ │ ├── car_service.py │ │ │ └── client_service.py │ │ ├── clients.txt │ │ └── cars.txt │ │ ├── Seminar11 │ │ ├── domain │ │ │ ├── __init__.py │ │ │ ├── car_rental_exception.py │ │ │ ├── validator_exception.py │ │ │ ├── rental.py │ │ │ └── client.py │ │ ├── repository │ │ │ ├── __init__.py │ │ │ └── repository_exception.py │ │ ├── service │ │ │ ├── __init__.py │ │ │ ├── car_rental_exception.py │ │ │ └── undo_service.py │ │ └── util.py │ │ └── Seminar12 │ │ ├── main.py │ │ ├── exceptions.py │ │ ├── game.py │ │ └── requirements.txt └── laboratory │ ├── __init__.py │ └── 915-1 │ ├── __init__.py │ └── fizzbuzz.py ├── .idea └── .gitignore └── README.md /src/lecture/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/laboratory/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/laboratory/915-1/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/examples/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group911/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group912/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_13/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_14/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_8/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_9/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_12/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_13/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_8/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_9/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar7/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar8/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar7/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar8/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar7/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar8/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/examples/ex29_modules/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_12/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_13/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_7/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_8/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar9/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar9/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/examples/ex30_modular_calc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/examples/ex30_modular_calc/ui/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/examples/ex36_rational_calc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/repo/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/services/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_9/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_9/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_9/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_9/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/service/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar9/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/examples/ex29_modules/rational/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/lecture/examples/ex30_modular_calc/domain/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/repository/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_13/sentinces.txt: -------------------------------------------------------------------------------- 1 | correct sentence 2 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_7/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Package for seminar 7 3 | """ 4 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_14/test_flights.txt: -------------------------------------------------------------------------------- 1 | 1,a,10:00,b,10:45 2 | 2,b,12:20,c,12:40 3 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_7/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | First implementation of a Tic Tac Toe game :) 3 | """ 4 | -------------------------------------------------------------------------------- /src/seminar/group916/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cs-ubbcluj-ro/FP-2024/HEAD/src/seminar/group916/.DS_Store -------------------------------------------------------------------------------- /src/laboratory/915-1/fizzbuzz.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cs-ubbcluj-ro/FP-2024/HEAD/src/laboratory/915-1/fizzbuzz.py -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/clients.txt: -------------------------------------------------------------------------------- 1 | 200,Gregory Bass 2 | 201,Jeremy Ford 3 | 202,Philip Miller 4 | 203,Heather Perez 5 | 204,Laura Dorsey -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/clients.txt: -------------------------------------------------------------------------------- 1 | 200,Gregory Bass 2 | 201,Jeremy Ford 3 | 202,Philip Miller 4 | 203,Heather Perez 5 | 204,Laura Dorsey -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/clients.txt: -------------------------------------------------------------------------------- 1 | 200,Gregory Bass 2 | 201,Jeremy Ford 3 | 202,Philip Miller 4 | 203,Heather Perez 5 | 204,Laura Dorsey -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/ui/cars.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cs-ubbcluj-ro/FP-2024/HEAD/src/seminar/group915/Seminar9/ui/cars.pickle -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/ui/cars.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cs-ubbcluj-ro/FP-2024/HEAD/src/seminar/group916/Seminar9/ui/cars.pickle -------------------------------------------------------------------------------- /src/seminar/group917/Seminar9/ui/cars.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cs-ubbcluj-ro/FP-2024/HEAD/src/seminar/group917/Seminar9/ui/cars.pickle -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/data/cars.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cs-ubbcluj-ro/FP-2024/HEAD/src/seminar/group915/Seminar9/data/cars.pickle -------------------------------------------------------------------------------- /src/seminar/group915/Seminar12/main.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar12.ui import UI 2 | 3 | def main(): 4 | ui = UI() 5 | ui.startGame() 6 | 7 | main() -------------------------------------------------------------------------------- /src/seminar/group916/Seminar12/main.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar12.ui import UI 2 | 3 | def main(): 4 | ui = UI() 5 | ui.startGame() 6 | 7 | main() -------------------------------------------------------------------------------- /src/seminar/group917/Seminar12/main.py: -------------------------------------------------------------------------------- 1 | from Seminar917.Seminar12.ui import UI 2 | 3 | def main(): 4 | ui = UI() 5 | ui.startGame() 6 | 7 | main() -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/recipes.txt: -------------------------------------------------------------------------------- 1 | 500,Basic Homemade Bread,101,20,102,30,103,5,104,10,100,1000 2 | 501,Tasty Cookies,105,175,102,175,106,3,107,175,108,5,109,5,103,2 3 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/settings.properties: -------------------------------------------------------------------------------- 1 | # what kind of repo 2 | repository=text 3 | # file names, if applicable 4 | ingredient_file=ingredients.txt 5 | recipes_file=recipes.txt -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/cars.txt: -------------------------------------------------------------------------------- 1 | 100,CJ 01 YUI,Audi A3 2 | 101,SJ 56 RGV,Toyota Hilux 3 | 102,B 567 QWN,Dacia Jogger 4 | 103,VS 66 PLO,Suzuki Vitara 5 | 104,CT 45 CFT,VW T-Roc 6 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_13/start.py: -------------------------------------------------------------------------------- 1 | from ui import Console 2 | from repository import Repository 3 | from services import Service 4 | 5 | repo=Repository() 6 | service=Service(repo) 7 | UI=Console(service) 8 | UI.run() -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/service/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self.__msg = msg 4 | 5 | def __str__(self): 6 | return str(self.__msg) -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/service/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self.__msg = msg 4 | 5 | def __str__(self): 6 | return str(self.__msg) -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/service/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self.__msg = msg 4 | 5 | def __str__(self): 6 | return str(self.__msg) -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/service/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self.__msg = msg 4 | 5 | def __str__(self): 6 | return str(self.__msg) 7 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/service/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self.__msg = msg 4 | 5 | def __str__(self): 6 | return str(self.__msg) 7 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/domain/exceptions.py: -------------------------------------------------------------------------------- 1 | class FlightApplicationException(Exception): 2 | pass 3 | 4 | class RepoError(FlightApplicationException): 5 | pass 6 | 7 | class ValidationError(FlightApplicationException): 8 | pass -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/domain/exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | class FlightApplicationException(Exception): 3 | pass 4 | 5 | class RepoError(FlightApplicationException): 6 | pass 7 | 8 | class ValidationError(FlightApplicationException): 9 | pass -------------------------------------------------------------------------------- /src/lecture/examples/ex30_modular_calc/rational_calc.py: -------------------------------------------------------------------------------- 1 | """ 2 | Start the calculator application 3 | """ 4 | 5 | from lecture.examples.ex30_modular_calc.ui.console import run 6 | 7 | # invoke the run method from the module ui.console 8 | 9 | 10 | run() 11 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_13/start.py: -------------------------------------------------------------------------------- 1 | from repository import Repository 2 | from services import Services 3 | from ui import UI 4 | 5 | def main(): 6 | repo = Repository() 7 | services = Services(repo) 8 | ui = UI(services) 9 | ui.run_main_menu() 10 | 11 | main() -------------------------------------------------------------------------------- /src/seminar/group914/seminar_13/sentences.txt: -------------------------------------------------------------------------------- 1 | anna has apples 2 | 3 | patricia has pears 4 | 5 | cars are fast 6 | 7 | planes are quick 8 | 9 | the quick brown fox jumps over the lazy dog 10 | 11 | anna has 12 | 13 | anna doesn't have apples 14 | 15 | marla has pears 16 | 17 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/domain/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self._message = msg 4 | 5 | def getMessage(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/domain/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self._message = msg 4 | 5 | def getMessage(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/domain/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self._message = msg 4 | 5 | def getMessage(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/domain/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self._message = msg 4 | 5 | def getMessage(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/domain/car_rental_exception.py: -------------------------------------------------------------------------------- 1 | class CarRentalException(Exception): 2 | def __init__(self, msg): 3 | self._message = msg 4 | 5 | def getMessage(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/repository/repository_exception.py: -------------------------------------------------------------------------------- 1 | class RepositoryException(Exception): 2 | def __init__(self, message): 3 | self._message = message 4 | 5 | def get_message(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/repository/repository_exception.py: -------------------------------------------------------------------------------- 1 | class RepositoryException(Exception): 2 | def __init__(self, message): 3 | self._message = message 4 | 5 | def get_message(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/repository/repository_exception.py: -------------------------------------------------------------------------------- 1 | class RepositoryException(Exception): 2 | def __init__(self, message): 3 | self._message = message 4 | 5 | def get_message(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/repository/repository_exception.py: -------------------------------------------------------------------------------- 1 | class RepositoryException(Exception): 2 | def __init__(self, message): 3 | self._message = message 4 | 5 | def get_message(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/repository/repository_exception.py: -------------------------------------------------------------------------------- 1 | class RepositoryException(Exception): 2 | def __init__(self, message): 3 | self._message = message 4 | 5 | def get_message(self): 6 | return self._message 7 | 8 | def __str__(self): 9 | return self._message -------------------------------------------------------------------------------- /src/seminar/group914/seminar_13/domain.py: -------------------------------------------------------------------------------- 1 | class Sentence: 2 | def __init__(self, sentence:str): 3 | self.__sentence=sentence 4 | 5 | @property 6 | def sentence(self): 7 | return self.__sentence 8 | 9 | def __str__(self): 10 | return f"sentence={self.sentence}" 11 | 12 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/ingredients.txt: -------------------------------------------------------------------------------- 1 | 100,Bread Flour (White 550),1000 2 | 101,Yeast (dry),500 3 | 102,Sugar (white),800 4 | 103,Salt (regular),200 5 | 104,Oil (canola),450 6 | 105,Butter,1000 7 | 106,Egg (chicken),500 8 | 107,Cake flour,1000 9 | 108,Baking powder,1200 10 | 109,Vanilla (extract),100 11 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_14/start.py: -------------------------------------------------------------------------------- 1 | from repository import FlightRepo 2 | from services import FlightServices 3 | from ui import ConsoleUI 4 | 5 | def main(): 6 | repo = FlightRepo("flights.txt") 7 | services = FlightServices(repo) 8 | ui = ConsoleUI(services) 9 | ui.run() 10 | 11 | main() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fundamentals of Programming 2024 - 2025 2 | This repository holds the lecture and seminar code examples. Repository structure: 3 | * `src/lecture/examples` - code examples for the lecture notes. 4 | * `src/lecture/live-coding` - live coding examples during the lecture. 5 | * `src/seminar/groupXXX` - seminar work with group `XXX` 6 | -------------------------------------------------------------------------------- /src/lecture/examples/ex25_function_call_visualisation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Add the code below to https://pythontutor.com/visualize.html 3 | Check the evolution of the call stack step by step 4 | """ 5 | 6 | 7 | def fib(n: int) -> int: 8 | if n < 2: 9 | return n 10 | return fib(n - 2) + fib(n - 1) 11 | 12 | 13 | print(fib(8)) 14 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/util.py: -------------------------------------------------------------------------------- 1 | def print_repos_with_message(msg, client_repo, car_repo, rent_repo): 2 | print("-" * 15 + msg + "-" * 15) 3 | if client_repo is not None: 4 | print("Clients:\n" + str(client_repo)) 5 | if car_repo is not None: 6 | print("Cars:\n" + str(car_repo)) 7 | if rent_repo is not None: 8 | print("Rentals:\n" + str(rent_repo)) -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/util.py: -------------------------------------------------------------------------------- 1 | def print_repos_with_message(msg, client_repo, car_repo, rent_repo): 2 | print("-" * 15 + msg + "-" * 15) 3 | if client_repo is not None: 4 | print("Clients:\n" + str(client_repo)) 5 | if car_repo is not None: 6 | print("Cars:\n" + str(car_repo)) 7 | if rent_repo is not None: 8 | print("Rentals:\n" + str(rent_repo)) -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/util.py: -------------------------------------------------------------------------------- 1 | def print_repos_with_message(msg, client_repo, car_repo, rent_repo): 2 | print("-" * 15 + msg + "-" * 15) 3 | if client_repo is not None: 4 | print("Clients:\n" + str(client_repo)) 5 | if car_repo is not None: 6 | print("Cars:\n" + str(car_repo)) 7 | if rent_repo is not None: 8 | print("Rentals:\n" + str(rent_repo)) -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/util.py: -------------------------------------------------------------------------------- 1 | def print_repos_with_message(msg, client_repo, car_repo, rent_repo): 2 | print("-" * 15 + msg + "-" * 15) 3 | if client_repo is not None: 4 | print("Clients:\n" + str(client_repo)) 5 | if car_repo is not None: 6 | print("Cars:\n" + str(car_repo)) 7 | if rent_repo is not None: 8 | print("Rentals:\n" + str(rent_repo)) 9 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/util.py: -------------------------------------------------------------------------------- 1 | def print_repos_with_message(msg, client_repo, car_repo, rent_repo): 2 | print("-" * 15 + msg + "-" * 15) 3 | if client_repo is not None: 4 | print("Clients:\n" + str(client_repo)) 5 | if car_repo is not None: 6 | print("Cars:\n" + str(car_repo)) 7 | if rent_repo is not None: 8 | print("Rentals:\n" + str(rent_repo)) 9 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/service/car_service.py: -------------------------------------------------------------------------------- 1 | from seminar.group913.seminar_10.repository.memory_repo import MemoryRepository 2 | from seminar.group913.seminar_9.domain.car import Car 3 | 4 | 5 | class CarService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, car_id: int) -> Car: 10 | return self._repo[car_id] 11 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/service/car_service.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_10.repository.memory_repo import MemoryRepository 2 | from seminar.group914.seminar_9.domain.car import Car 3 | 4 | 5 | class CarService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, car_id: int) -> Car: 10 | return self._repo[car_id] 11 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/service/client_service.py: -------------------------------------------------------------------------------- 1 | from seminar.group913.seminar_10.domain.client import Client 2 | from seminar.group913.seminar_10.repository.memory_repo import MemoryRepository 3 | 4 | 5 | class ClientService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, client_id: int) -> Client: 10 | return self._repo[client_id] 11 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/service/client_service.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_10.domain.client import Client 2 | from seminar.group914.seminar_10.repository.memory_repo import MemoryRepository 3 | 4 | 5 | class ClientService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, client_id: int) -> Client: 10 | return self._repo[client_id] 11 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/service/rental_service.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_10.domain.rental import Rental 2 | from seminar.group914.seminar_10.repository.memory_repo import MemoryRepository 3 | 4 | 5 | class RentalService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, rental_id: int) -> Rental: 10 | return self._repo[rental_id] 11 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/service/car_service.py: -------------------------------------------------------------------------------- 1 | from seminar10.repository.memory_repo import MemoryRepository 2 | from seminar10.domain.car import Car 3 | 4 | 5 | class CarService: 6 | def __init__(self, repo: MemoryRepository): 7 | self.__repo = repo 8 | 9 | def get(self, car_id: int) -> Car: 10 | return self.__repo[car_id] 11 | 12 | def get_all(self): 13 | return self.__repo -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/service/car_service.py: -------------------------------------------------------------------------------- 1 | from seminar10.repository.memory_repo import MemoryRepository 2 | from seminar10.domain.car import Car 3 | 4 | 5 | class CarService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, car_id: int) -> Car: 10 | return self._repo[car_id] 11 | 12 | def getAll(self): 13 | return self._repo -------------------------------------------------------------------------------- /src/seminar/group914/seminar_13/services.py: -------------------------------------------------------------------------------- 1 | from domain import Sentence 2 | from repository import Repository 3 | 4 | class Service: 5 | def __init__(self, repo:Repository): 6 | self.__repo=repo 7 | 8 | def add(self, sentence_from_ui:str): 9 | sentence=Sentence(sentence_from_ui) 10 | self.__repo.add(sentence) 11 | 12 | def get_all(self): 13 | return self.__repo.get_all() 14 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/service/client_service.py: -------------------------------------------------------------------------------- 1 | from seminar10.domain.client import Client 2 | from seminar10.repository.memory_repo import MemoryRepository 3 | 4 | 5 | class ClientService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, client_id: int) -> Client: 10 | return self._repo[client_id] 11 | 12 | def getAll(self): 13 | return self._repo -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/service/client_service.py: -------------------------------------------------------------------------------- 1 | from seminar10.domain.client import Client 2 | from seminar10.repository.memory_repo import MemoryRepository 3 | 4 | 5 | class ClientService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, client_id: int) -> Client: 10 | return self._repo[client_id] 11 | 12 | def getAll(self): 13 | return self._repo -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/service/client_service.py: -------------------------------------------------------------------------------- 1 | from seminar10.domain.client import Client 2 | from seminar10.repository.memory_repo import MemoryRepository 3 | 4 | 5 | class ClientService: 6 | def __init__(self, repo: MemoryRepository): 7 | self.__repo = repo 8 | 9 | def get(self, client_id: int) -> Client: 10 | return self.__repo[client_id] 11 | 12 | def get_all(self): 13 | return self.__repo -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/domain/validator_exception.py: -------------------------------------------------------------------------------- 1 | class ValidatorException(Exception): 2 | def __init__(self, messageList): 3 | self._messageList = messageList 4 | 5 | def getMessage(self): 6 | return self._messageList 7 | 8 | def __str__(self): 9 | result = "" 10 | for message in self.getMessage(): 11 | result += message 12 | result += "\n" 13 | return result -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/domain/validator_exception.py: -------------------------------------------------------------------------------- 1 | class ValidatorException(Exception): 2 | def __init__(self, messageList): 3 | self._messageList = messageList 4 | 5 | def getMessage(self): 6 | return self._messageList 7 | 8 | def __str__(self): 9 | result = "" 10 | for message in self.getMessage(): 11 | result += message 12 | result += "\n" 13 | return result -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/domain/validator_exception.py: -------------------------------------------------------------------------------- 1 | class ValidatorException(Exception): 2 | def __init__(self, messageList): 3 | self._messageList = messageList 4 | 5 | def getMessage(self): 6 | return self._messageList 7 | 8 | def __str__(self): 9 | result = "" 10 | for message in self.getMessage(): 11 | result += message 12 | result += "\n" 13 | return result -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/domain/validator_exception.py: -------------------------------------------------------------------------------- 1 | class ValidatorException(Exception): 2 | def __init__(self, messageList): 3 | self._messageList = messageList 4 | 5 | def getMessage(self): 6 | return self._messageList 7 | 8 | def __str__(self): 9 | result = "" 10 | for message in self.getMessage(): 11 | result += message 12 | result += "\n" 13 | return result 14 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/domain/validator_exception.py: -------------------------------------------------------------------------------- 1 | class ValidatorException(Exception): 2 | def __init__(self, messageList): 3 | self._messageList = messageList 4 | 5 | def getMessage(self): 6 | return self._messageList 7 | 8 | def __str__(self): 9 | result = "" 10 | for message in self.getMessage(): 11 | result += message 12 | result += "\n" 13 | return result 14 | -------------------------------------------------------------------------------- /src/lecture/examples/ex10_exponential_search.py: -------------------------------------------------------------------------------- 1 | from ex09_binary_search import binary_search_impl 2 | 3 | 4 | def exponential_search(data: list, key): 5 | if len(data) == 0 or data[0] > key or data[-1] < key: 6 | return -1 7 | 8 | if data[0] == key: 9 | return 0 10 | 11 | i = 1 12 | while i < len(data) and data[i] <= key: 13 | i = i * 2 14 | 15 | return binary_search_impl(data, key, i // 2, min(i, len(data) - 1)) 16 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_7/test.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_7.board import create_board, is_won_board, is_full_board, move_board, get_symbol_board 2 | 3 | 4 | # import seminar.group914.seminar_7.board 5 | 6 | def test_board(): 7 | b = create_board() 8 | 9 | assert is_won_board(b) is False 10 | assert is_full_board(b) is False 11 | 12 | move_board(b, 'X', 1, 1) 13 | assert get_symbol_board(b, 1, 1) == 'X' 14 | # TODO write more tests 15 | -------------------------------------------------------------------------------- /src/lecture/examples/ex29_modules/rational/rational_list.py: -------------------------------------------------------------------------------- 1 | """ 2 | Docstring for Rational number represented using a list 3 | 4 | Created on Oct 21, 2018 5 | @author: Arthur 6 | """ 7 | from math import gcd 8 | 9 | 10 | def create_rational(nom, den=1): 11 | if den == 0: 12 | raise ValueError("Denominator cannot be 0") 13 | d = gcd(nom, den) 14 | return [nom // d, den // d] 15 | 16 | 17 | def get_numerator(q): 18 | return q[0] 19 | 20 | 21 | def get_denominator(q): 22 | return q[1] 23 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/domain/myTime.py: -------------------------------------------------------------------------------- 1 | from datetime import time 2 | 3 | class MyTime(time): 4 | def __sub__(self, other): 5 | if not isinstance(other, time): 6 | raise TypeError("Cannot subtract time from " + type(other)) 7 | return (self.hour - other.hour) * 60 + self.minute - other.minute 8 | 9 | def __str__(self): 10 | h = self.hour 11 | m = self.minute 12 | return (str(h) if h > 9 else ("0" + str(h))) + ":" + (str(m) if m > 9 else ("0" + str(m))) 13 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/domain/myTime.py: -------------------------------------------------------------------------------- 1 | from datetime import time 2 | 3 | class MyTime(time): 4 | def __sub__(self, other): 5 | if not isinstance(other, time): 6 | raise TypeError("Cannot subtract time from " + type(other)) 7 | return (self.hour - other.hour) * 60 + self.minute - other.minute 8 | 9 | def __str__(self): 10 | h = self.hour 11 | m = self.minute 12 | return (str(h) if h > 9 else ("0" + str(h))) + ":" + (str(m) if m > 9 else ("0" + str(m))) 13 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/domain/myTime.py: -------------------------------------------------------------------------------- 1 | from datetime import time 2 | 3 | class MyTime(time): 4 | def __sub__(self, other): 5 | if not isinstance(other, time): 6 | raise TypeError("Cannot subtract time from " + type(other)) 7 | return (self.hour - other.hour) * 60 + self.minute - other.minute 8 | 9 | def __str__(self): 10 | h = self.hour 11 | m = self.minute 12 | return (str(h) if h > 9 else ("0" + str(h))) + ":" + (str(m) if m > 9 else ("0" + str(m))) 13 | -------------------------------------------------------------------------------- /src/lecture/examples/ex29_modules/rational/rational_dict.py: -------------------------------------------------------------------------------- 1 | """ 2 | Docstring for Rational number represented using a dict 3 | 4 | Created on Oct 21, 2018 5 | @author: Arthur 6 | """ 7 | import math 8 | 9 | 10 | def create_rational(nom, den=1): 11 | if den == 0: 12 | raise ValueError("Denominator cannot be 0") 13 | 14 | d = math.gcd(nom, den) 15 | return {"nom": nom // d, "denom": den // d} 16 | 17 | 18 | def get_numerator(q): 19 | return q["nom"] 20 | 21 | 22 | def get_denominator(q): 23 | return q["denom"] 24 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/test/test_ingredient.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | 3 | from lecture.livecoding.lecture_9.domain.ingredient import Ingredient 4 | 5 | 6 | class TestIngredient(TestCase): 7 | 8 | def test_ingredient(self): 9 | ingr = Ingredient(100, "Sugar", 100) 10 | self.assertEqual(ingr.id, 101) 11 | self.assertEqual(ingr.name, "Sugar") 12 | 13 | def test_ingredient_quantity(self): 14 | ingr = Ingredient(100, "Sugar", 100) 15 | self.assertEqual(ingr.quantity, 100) 16 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/main.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar14.domain.validator import FlightValidator 2 | from Seminar916.Seminar14.repository.textRepository import TextRepository 3 | from Seminar916.Seminar14.service.flightService import FlightService 4 | from Seminar916.Seminar14.ui.console import UI 5 | 6 | if __name__=="__main__": 7 | flightRepository = TextRepository() 8 | flightValidator = FlightValidator() 9 | flightService = FlightService(flightRepository, flightValidator) 10 | 11 | ui = UI(flightService) 12 | ui.start() -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/main.py: -------------------------------------------------------------------------------- 1 | from Seminar917.Seminar14.domain.validator import FlightValidator 2 | from Seminar917.Seminar14.repository.textRepository import TextRepository 3 | from Seminar917.Seminar14.service.flightService import FlightService 4 | from Seminar917.Seminar14.ui.console import UI 5 | 6 | if __name__=="__main__": 7 | flightRepository = TextRepository() 8 | flightValidator = FlightValidator() 9 | flightService = FlightService(flightRepository, flightValidator) 10 | 11 | ui = UI(flightService) 12 | ui.start() -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/main.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar14.domain.validator import FlightValidator 2 | from Seminar915.Seminar14.repository.textRepository import FlightRepository 3 | from Seminar915.Seminar14.service.flightService import FlightService 4 | from Seminar915.Seminar14.ui.console import UI 5 | 6 | if __name__=="__main__": 7 | flightRepository = FlightRepository() 8 | flightValidator = FlightValidator() 9 | flightService = FlightService(flightRepository, flightValidator) 10 | 11 | ui = UI(flightService) 12 | ui.start() -------------------------------------------------------------------------------- /src/seminar/group916/Seminar12/exceptions.py: -------------------------------------------------------------------------------- 1 | class BoardExceptions(Exception): 2 | def __init__(self, message): 3 | self.__message = message 4 | 5 | def __str__(self): 6 | return self.__message 7 | 8 | 9 | class OutOfBoundsExceptions(BoardExceptions): 10 | def __init__(self): 11 | super().__init__("Position is out of bounds") 12 | 13 | 14 | class AlreadyHitExceptions(BoardExceptions): 15 | def __init__(self): 16 | super().__init__("Position was already hit") 17 | 18 | class GameOverException(Exception): 19 | pass -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/test/test_memory_repo.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | 3 | from lecture.livecoding.lecture_9.domain.ingredient import Ingredient 4 | from lecture.livecoding.lecture_9.repo.bakery_memory_repo import BakeryObjectMemoryRepo 5 | 6 | 7 | class TestBakeryMemoryRepo(TestCase): 8 | def test_repo(self): 9 | repo = BakeryObjectMemoryRepo() 10 | self.assertEqual(len(repo), 0) 11 | repo.add(Ingredient(100, "Sugar", 100)) 12 | repo.add(Ingredient(101, "Spice", 100)) 13 | self.assertEqual(len(repo), 2) 14 | -------------------------------------------------------------------------------- /src/lecture/examples/ex26_parameter_passing.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Sep 29, 2016 3 | 4 | @author: http://www.python-course.eu/passing_arguments.php 5 | """ 6 | 7 | """ 8 | Example for parameter passing. 9 | Use the locals() and globals() functions to better 10 | understand what goes on 11 | """ 12 | 13 | 14 | def references_demo(x: int): 15 | print("2. x=", x, " id=", id(x)) 16 | x = 42 17 | print("3. x=", x, " id=", id(x)) 18 | 19 | 20 | x = 10 21 | print("1. x=", x, " id=", id(x)) 22 | 23 | references_demo(x) 24 | print("4. x=", x, " id=", id(x)) 25 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar12/exceptions.py: -------------------------------------------------------------------------------- 1 | 2 | class BoardException(Exception): 3 | def __init__(self, message): 4 | self.__message = message 5 | 6 | def __str__(self): 7 | return self.__message 8 | 9 | class OutOfBoundsException(BoardException): 10 | def __init__(self): 11 | super().__init__("Position out of bounds") 12 | 13 | class AlreadyHitException(BoardException): 14 | def __init__(self): 15 | super().__init__("Position already hit") 16 | #BoardException.__init__("Position already hit") 17 | 18 | class GameOver(Exception): 19 | pass -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/service/car_service.py: -------------------------------------------------------------------------------- 1 | from seminar10.repository.memory_repo import MemoryRepository 2 | from seminar10.domain.car import Car 3 | 4 | 5 | class CarService: 6 | def __init__(self, repo: MemoryRepository): 7 | self._repo = repo 8 | 9 | def get(self, car_id: int) -> Car: 10 | return self._repo[car_id] 11 | 12 | def getAll(self): 13 | return self._repo 14 | 15 | def add(self, id: int, licensePlate: str, brand: str, model: str, color: str): 16 | newCar = Car(id, licensePlate, brand, model, color) 17 | self._repo.add(newCar) -------------------------------------------------------------------------------- /src/seminar/group917/Seminar7/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | from Seminar917.Seminar7.board import moveBoard, getBoardValue 4 | 5 | 6 | def humanMove(board, x: int, y: int): 7 | moveBoard(board, x, y, 'X') 8 | 9 | def getNextComputerMove(board): 10 | #TODO: implement a more complex version for this, preventing 11 | # the human's next moves 12 | 13 | found = False 14 | while not found: 15 | x = randint(0, 2) 16 | y = randint(0, 2) 17 | if getBoardValue(board, x, y) == 0: 18 | return x, y 19 | 20 | def computerMove(board): 21 | x, y = getNextComputerMove(board) 22 | moveBoard(board, x, y, 'O') -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | About undo/redo using the Command pattern 3 | https://refactoring.guru/design-patterns/command 4 | 5 | 1. Undo/redo only operations that change data (add/remove/update) 6 | 2. We must keep a list/stack of all program operations that we want undone 7 | -> Each time we have an operations we have to record it for undo 8 | -> undo is always the opposite operation 9 | -> redo is the operation itself (redo is only available after at least 1 undo) 10 | 3. If one or more undo operations are followed by a new operation (not undo/redo), redo is no longer 11 | available 12 | """ 13 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/service/flightService.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar14.domain.flight import Flight 2 | from Seminar915.Seminar14.domain.validator import FlightValidator 3 | from Seminar915.Seminar14.repository.textRepository import FlightRepository 4 | 5 | 6 | class FlightService: 7 | def __init__(self, flightRepository: FlightRepository, validator: FlightValidator): 8 | self.__repository = flightRepository 9 | self.__validator = validator 10 | 11 | def add(self, flight: Flight): 12 | self.__validator.validate(flight) 13 | self.__repository.add(flight) 14 | 15 | def getAll(self): 16 | return self.__repository.getAll() -------------------------------------------------------------------------------- /src/seminar/group916/Seminar7/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | from Seminar916.Seminar7.board import moveBoard, getBoardValue 4 | 5 | 6 | def humanMove(board, x : int, y: int): 7 | moveBoard(board, x, y, 'X') 8 | 9 | def getNextComputerMove(board): 10 | # TODO: Implement a more complex algorithm such that it might prevent the next moves of the human 11 | found = False 12 | 13 | while not found: 14 | x = randint(0, 2) 15 | y = randint(0, 2) 16 | 17 | if getBoardValue(board, x, y) == 0: 18 | return x, y 19 | 20 | def computerMove(board): 21 | x, y = getNextComputerMove(board) 22 | moveBoard(board, x, y, 'O') 23 | 24 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/domain/validator.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar14.domain.exceptions import ValidationError 2 | 3 | class FlightValidator: 4 | def validate(self, flight): 5 | errors = [] 6 | 7 | if flight.departureCity == flight.arrivalCity: 8 | errors.append("Flight should arrive at different airport") 9 | if flight.departureTime > flight.arrivalTime: 10 | errors.append("Flight should depart before arrival") 11 | elif not 15 <= flight.arrivalTime - flight.departureTime <= 90: 12 | errors.append("Flights must be between 15 and 90 minutes!") 13 | if len(errors) > 0: 14 | raise ValidationError(errors) -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/service/flightService.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar14.domain.validator import FlightValidator 2 | from Seminar916.Seminar14.repository.textRepository import TextRepository 3 | 4 | 5 | class FlightService: 6 | def __init__(self, flightRepository: TextRepository, flightvalidator: FlightValidator): 7 | self.__repository = flightRepository 8 | self.__validator = flightvalidator 9 | 10 | def add(self, flight): 11 | self.__validator.validate(flight) 12 | self.__repository.add(flight) 13 | 14 | def remove(self, identifier): 15 | self.__repository.remove(identifier) 16 | 17 | def getAll(self): 18 | return self.__repository.getAll() -------------------------------------------------------------------------------- /src/lecture/examples/ex08_sequential_search.py: -------------------------------------------------------------------------------- 1 | def search_iter(data: list, key): 2 | for i in range(len(data)): 3 | if data[i] == key: 4 | return i 5 | return -1 6 | 7 | 8 | def search_rec(data: list, key, pos: int = 0): 9 | if len(data) > 997: 10 | # The initial execution of the current module and 11 | # initial method call are already on the stack, so we have fewer than 12 | # 1000 recursive calls available in the default Python implementation ;) 13 | raise ValueError("Will overflow the Python stack") 14 | 15 | if 0 > pos or pos >= len(data): 16 | return -1 17 | if data[pos] == key: 18 | return key 19 | return search_rec(data, key, pos + 1) 20 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/domain/bakery_product.py: -------------------------------------------------------------------------------- 1 | from lecture.livecoding.lecture_9.domain.bakery_object import BakeryObject 2 | from lecture.livecoding.lecture_9.domain.recipe import Recipe 3 | 4 | 5 | class BakeryProduct(BakeryObject): 6 | def __init__(self, object_id: int, name: str, quantity: int, recipe: Recipe): 7 | super().__init__(object_id, name) 8 | self.__recipe = recipe 9 | self.__quantity = quantity 10 | 11 | @property 12 | def recipe(self): 13 | return self.__recipe 14 | 15 | @property 16 | def quantity(self): 17 | return self.__quantity 18 | 19 | @quantity.setter 20 | def quantity(self, new_value: int): 21 | self.__quantity = new_value 22 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/domain/validator.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar14.domain.flight import Flight 2 | 3 | class ValidationError(Exception): 4 | pass 5 | 6 | class FlightValidator: 7 | def validate(self, flight: Flight): 8 | errors = [] 9 | 10 | if flight.departureCity == flight.arrivalCity: 11 | errors.append("Flight should arrive at different airport") 12 | if flight.departureTime > flight.arrivalTime: 13 | errors.append("Flight should depart before arrival") 14 | elif not 15 <= flight.arrivalTime - flight.departureTime <= 90: 15 | errors.append("Flights must be between 15 and 90 minutes!") 16 | if len(errors) > 0: 17 | raise ValidationError(errors) -------------------------------------------------------------------------------- /src/lecture/examples/ex27_side_effects.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Sep 29, 2016 3 | 4 | @author: http://www.python-course.eu/passing_arguments.php 5 | """ 6 | 7 | """ 8 | Example for function side effects. Run the code below calling each of 9 | the functions in turn. Examine the result 10 | """ 11 | 12 | 13 | def no_side_effect(lst): 14 | print(2, id(lst), lst) 15 | lst = [0, 1, 2, 3] 16 | print(3, id(lst), lst) 17 | 18 | 19 | def side_effect(lst): 20 | print(5, id(lst), lst) 21 | lst.append(999) 22 | print(6, id(lst), lst) 23 | 24 | 25 | my_list = [0, 1, 2] 26 | print(1, id(my_list), my_list) 27 | no_side_effect(my_list) 28 | print(4, id(my_list), my_list) 29 | side_effect(my_list) 30 | print(7, id(my_list), my_list) 31 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/repository/memoryRepository.py: -------------------------------------------------------------------------------- 1 | from Seminar917.Seminar14.domain.exceptions import RepoError 2 | from Seminar917.Seminar14.domain.flight import Flight 3 | 4 | class MemoryRepository: 5 | def __init__(self): 6 | self._data = {} 7 | 8 | def add(self, flight: Flight): 9 | if flight.identifier in self._data.keys(): 10 | raise RepoError("Flight already exists") 11 | 12 | self._data[flight.identifier] = flight 13 | 14 | def remove(self, identifier: str) -> Flight: 15 | if identifier not in self._data.keys(): 16 | raise RepoError("Flight does not exist") 17 | return self._data.pop(identifier) 18 | 19 | def getAll(self): 20 | return self._data.values() -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/domain/ingredient.py: -------------------------------------------------------------------------------- 1 | from lecture.livecoding.lecture_9.domain.bakery_object import BakeryObject 2 | 3 | 4 | class Ingredient(BakeryObject): 5 | def __init__(self, ingredient_id: int, name: str, quantity: int): 6 | super().__init__(ingredient_id, name) 7 | self.__quantity = quantity 8 | 9 | @property 10 | def quantity(self): 11 | return self.__quantity 12 | 13 | @quantity.setter 14 | def quantity(self, new_quantity): 15 | self.__quantity = new_quantity 16 | 17 | def __str__(self): 18 | # super() - goes to the base class of this 19 | # return super().__str__() + "abcd" 20 | return f"Ingredient id={self.id} is {self.name}, quantity={self.quantity}" 21 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/domain/validator.py: -------------------------------------------------------------------------------- 1 | from Seminar917.Seminar14.domain.flight import Flight 2 | from Seminar917.Seminar14.domain.exceptions import ValidationError 3 | 4 | class FlightValidator: 5 | def validate(self, flight: Flight): 6 | errors = [] 7 | 8 | if flight.departureCity == flight.arrivalCity: 9 | errors.append("Flight should arrive at different airport") 10 | if flight.departureTime > flight.arrivalTime: 11 | errors.append("Flight should depart before arrival") 12 | elif not 15 <= flight.arrivalTime - flight.departureTime <= 90: 13 | errors.append("Flights must be between 15 and 90 minutes!") 14 | if len(errors) > 0: 15 | raise ValidationError(errors) -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/repository/memoryRepository.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar14.domain.exceptions import RepoError 2 | from Seminar916.Seminar14.domain.flight import Flight 3 | 4 | class MemoryRepository: 5 | def __init__(self): 6 | self._data = {} 7 | 8 | def add(self, flight: Flight): 9 | if flight.identifier in self._data.keys(): 10 | raise RepoError("Flight already exists") 11 | 12 | self._data[flight.identifier] = flight 13 | 14 | def getAll(self): 15 | return self._data.values() 16 | 17 | def remove(self, identifier: str) -> Flight: 18 | if identifier not in self._data.keys(): 19 | raise RepoError("Flight does not exist") 20 | 21 | return self._data.pop(identifier) -------------------------------------------------------------------------------- /src/lecture/examples/ex01_basic_syntax.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Sep 23, 2016 3 | 4 | @author: Arthur 5 | """ 6 | 7 | """ 8 | Print a message to the console 9 | """ 10 | print("Hello world!") 11 | 12 | """ 13 | Read from the console 14 | """ 15 | a = input("Enter the first number: ") 16 | b = input("Enter the second number: ") 17 | 18 | """ 19 | NB! 20 | What is printed out and why? 21 | """ 22 | print(a + b) 23 | 24 | # This is a line comment 25 | 26 | """ 27 | NB! 28 | What does this do? 29 | """ 30 | x = int(a) 31 | y = int(b) 32 | 33 | print(x + y) 34 | 35 | """ 36 | NB! 37 | This is all very confusing... how do I know what is what? 38 | """ 39 | print("this should be a string - ", type(a)) 40 | print("and this is an integer -", type(x)) -------------------------------------------------------------------------------- /src/seminar/group915/Seminar7/game.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar7.board import moveBoard, getBoard 2 | from random import randint 3 | 4 | def humanMove(board, x: int, y: int): 5 | moveBoard(board, x, y, 'X') 6 | 7 | def computerMove(board): 8 | x, y = getNextComputerMove(board) 9 | moveBoard(board, x, y, 'O') 10 | 11 | def getNextComputerMove(board): 12 | """ 13 | Decides where the computer places its next move 14 | TODO: Implement a version that prevents human's moves 15 | :param board: the board 16 | :return: x, y - the positions of the next move 17 | """ 18 | found = False 19 | while not found: 20 | x = randint(0, 2) 21 | y = randint(0, 2) 22 | 23 | if getBoard(board, x, y) == 0: 24 | return x, y 25 | 26 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/rentals.txt: -------------------------------------------------------------------------------- 1 | 300,102,203,2024-07-27,2024-08-02 2 | 301,101,204,2024-06-20,2024-06-28 3 | 302,101,200,2024-06-17,2024-06-18 4 | 303,102,200,2024-03-18,2024-03-24 5 | 304,104,200,2024-03-26,2024-04-02 6 | 305,101,204,2024-02-14,2024-02-15 7 | 306,104,202,2024-03-25,2024-04-03 8 | 307,101,203,2024-03-08,2024-03-11 9 | 308,103,203,2024-04-16,2024-04-26 10 | 309,102,204,2024-09-19,2024-09-25 11 | 310,102,202,2024-05-14,2024-05-23 12 | 311,101,202,2024-04-02,2024-04-05 13 | 312,102,202,2024-05-03,2024-05-07 14 | 313,101,201,2024-03-22,2024-03-27 15 | 314,101,201,2024-03-29,2024-04-05 16 | 315,100,203,2024-05-17,2024-05-20 17 | 316,100,202,2024-08-12,2024-08-16 18 | 317,103,204,2024-03-26,2024-03-31 19 | 318,102,202,2024-09-03,2024-09-09 20 | 319,102,204,2024-12-09,2024-12-16 21 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/rentals.txt: -------------------------------------------------------------------------------- 1 | 300,100,201,2024-01-28,2024-01-30 2 | 301,102,200,2024-07-16,2024-07-18 3 | 302,100,201,2024-08-21,2024-08-22 4 | 303,104,200,2024-08-04,2024-08-07 5 | 304,101,202,2024-11-05,2024-11-15 6 | 305,101,204,2024-02-11,2024-02-18 7 | 306,100,201,2024-08-14,2024-08-16 8 | 307,100,204,2024-03-20,2024-03-26 9 | 308,100,202,2024-06-19,2024-06-27 10 | 309,104,203,2024-11-09,2024-11-14 11 | 310,104,200,2024-03-10,2024-03-20 12 | 311,104,204,2024-04-17,2024-04-27 13 | 312,100,200,2024-07-14,2024-07-19 14 | 313,100,200,2024-10-18,2024-10-24 15 | 314,102,202,2024-11-22,2024-11-30 16 | 315,101,204,2024-06-29,2024-07-03 17 | 316,102,204,2024-08-12,2024-08-14 18 | 317,103,202,2024-02-25,2024-02-28 19 | 318,102,201,2024-02-01,2024-02-05 20 | 319,103,204,2024-08-25,2024-08-27 21 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/service/flightService.py: -------------------------------------------------------------------------------- 1 | from Seminar917.Seminar14.domain.flight import Flight 2 | from Seminar917.Seminar14.domain.validator import FlightValidator 3 | from Seminar917.Seminar14.repository.textRepository import TextRepository 4 | 5 | 6 | class FlightService: 7 | def __init__(self, flightRepository: TextRepository, flightvalidator: FlightValidator): 8 | self.__repository = flightRepository 9 | self.__validator = flightvalidator 10 | 11 | def add(self, flight: Flight): 12 | self.__validator.validate(flight) 13 | self.__repository.add(flight) 14 | 15 | def remove(self, identifier: str) -> Flight: 16 | return self.__repository.remove(identifier) 17 | 18 | def getAll(self): 19 | return self.__repository.getAll() -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_2.py: -------------------------------------------------------------------------------- 1 | def fact(n: int) -> int: 2 | # Base case of recursion 3 | if n == 0: 4 | return 1 5 | 6 | # Recursion progresses towards the base case 7 | return n * fact(n - 1) 8 | 9 | 10 | # for i in range(1050): 11 | # print(i, fact(i)) 12 | 13 | 14 | def fib(n: int) -> int: 15 | if n < 2: 16 | return 1 17 | 18 | return fib(n - 2) + fib(n - 1) 19 | 20 | 21 | # key 0 has associated value 1 22 | # key 1 has associated value 1 23 | cache = {0: 1, 1: 1} 24 | 25 | 26 | def fib_cached(n: int) -> int: 27 | if n in cache: 28 | return cache[n] 29 | 30 | cache[n] = fib_cached(n - 2) + fib_cached(n - 1) 31 | return cache[n] 32 | 33 | 34 | for i in range(35): 35 | # print(i, fib(i)) 36 | print(i, fib_cached(i)) 37 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/services/services.py: -------------------------------------------------------------------------------- 1 | from lecture.livecoding.lecture_9.domain.bakery_product import BakeryProduct 2 | from lecture.livecoding.lecture_9.repo.bakery_memory_repo import BakeryObjectMemoryRepo 3 | 4 | 5 | class IngredientService: 6 | def __init__(self, repository: BakeryObjectMemoryRepo): 7 | self.__repo = repository 8 | 9 | 10 | class RecipeService: 11 | def __init__(self, repository: BakeryObjectMemoryRepo): 12 | self.__repo = repository 13 | 14 | 15 | class BakeryProductService: 16 | def __init__(self, repository: BakeryObjectMemoryRepo): 17 | self.__repo = repository 18 | 19 | def add(self, bakery_product: BakeryProduct): 20 | pass 21 | 22 | def bake(self, bakery_product: BakeryProduct, quantity: int): 23 | pass 24 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar12/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | from Seminar915.Seminar12.board import BoardExceptions 4 | 5 | 6 | class ComputerPlayer: 7 | def __init__(self, ownBoard, opponentBoard): 8 | self.__ownBoard = ownBoard 9 | self.__opponentBoard = opponentBoard 10 | 11 | def placeShip(self): 12 | try: 13 | row = randint(0, self.__ownBoard.size - 1) 14 | column = randint(0, self.__ownBoard.size - 3) 15 | self.__ownBoard.placeShip(row, column) 16 | except BoardExceptions: 17 | self.placeShip() 18 | 19 | def hit(self): 20 | row = randint(0, self.__ownBoard.size - 1) 21 | column = randint(0, self.__ownBoard.size - 1) 22 | self.__opponentBoard.hit(row, column) 23 | return row, column -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/domain/bakery_object.py: -------------------------------------------------------------------------------- 1 | class BakeryObject(object): # a class is by default derived from Python's object class 2 | def __init__(self, object_id: int, name: str): 3 | self.__id = object_id 4 | self._name = name 5 | 6 | # id is a read-only property (it has no setter) 7 | @property 8 | def id(self): 9 | return self.__id 10 | 11 | @property 12 | def name(self): 13 | return self._name 14 | 15 | @name.setter 16 | def name(self, new_value: str): 17 | # NOTE We can add proper validation here 18 | self._name = new_value 19 | 20 | def __str__(self): 21 | # super() - goes to the base class of this 22 | # return super().__str__() + "abcd" 23 | return f"Bakery object id={self.id} is {self.name}" 24 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_14/flights.txt: -------------------------------------------------------------------------------- 1 | RO650,Cluj,05:45,Bucuresti,06:40 2 | OB3302,Cluj,07:15,Bucuresti,08:15 3 | SLD322,Timisoara,09:05,Cluj,10:00 4 | RO643,Bucuresti,10:15,Cluj,11:10 5 | RO734,Timisoara,10:45,Iasi,12:25 6 | KL2710,Timisoara,14:25,Bucuresti,15:40 7 | RO745,Cluj,12:50,Iasi,14:05 8 | RO746,Iasi,14:30,Cluj,15:50 9 | RO647,Bucuresti,18:05,Cluj,19:00 10 | KL2706,Bucuresti,18:10,Timisoara,19:05 11 | RO733,Iasi,08:30,Timisoara,10:20 12 | SLD363,Cluj,19:35,Timisoara,20:30 13 | RO649,Bucuresti,21:55,Cluj,22:50 14 | OB3101,Bucuresti,22:55,Cluj,23:55 15 | RP621,Bucuresti,07:30,Oradea,08:55 16 | RO622,Oradea,09:20,Bucuresti,10:40 17 | RO627,Bucuresti,17:55,Oradea,19:15 18 | RO628,Oradea,19:45,Bucuresti,21:05 19 | XL897,TgMures,08:55,Oradea,09:30 20 | XL898,Oradea,20:45,TgMures,21:25 21 | LH012,Iasi,14:35,Oradea,15:35 22 | LH013,Oradea,17:00,Iasi,18:10 23 | -------------------------------------------------------------------------------- /src/lecture/examples/ex14_merge_sort.py: -------------------------------------------------------------------------------- 1 | """ 2 | Merge Sort implementation 3 | """ 4 | 5 | 6 | def merge_sort(array): 7 | if len(array) < 2: 8 | return array 9 | 10 | mid = len(array) // 2 11 | left_half = array[:mid] 12 | right_half = array[mid:] 13 | merge_sort(left_half) 14 | merge_sort(right_half) 15 | merge(left_half, right_half, array) 16 | 17 | 18 | def merge(l1, l2, lrez): 19 | i = 0 20 | j = 0 21 | l = [] 22 | while i < len(l1) and j < len(l2): 23 | if l1[i] < l2[j]: 24 | l.append(l1[i]) 25 | i = i + 1 26 | else: 27 | l.append(l2[j]) 28 | j = j + 1 29 | while i < len(l1): 30 | l.append(l1[i]) 31 | i = i + 1 32 | while j < len(l2): 33 | l.append(l2[j]) 34 | j = j + 1 35 | lrez.clear() 36 | lrez.extend(l) 37 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client(object): 2 | def __init__(self, clientId, name): 3 | self.__id = clientId 4 | self._name = name 5 | 6 | @property 7 | def id(self): 8 | return self.__id 9 | 10 | @property 11 | def name(self): 12 | return self._name 13 | 14 | @name.setter 15 | def name(self, value): 16 | self._name = value 17 | 18 | def __eq__(self, z): 19 | # don't compare apples to oranges 20 | if type(z) != Client: 21 | return False 22 | # just look at the id field 23 | return self.id == z.id 24 | 25 | def __str__(self): 26 | return f"{self.id} - {self.name}" 27 | 28 | 29 | if __name__ == "__main__": 30 | c1 = Client(1000, "Popescu Ana") 31 | c2 = Client(1001, "Popescu Ana") 32 | print(c1 == c2) 33 | print({1000: c1, 1001: c2}) -------------------------------------------------------------------------------- /src/seminar/group914/seminar_14.py: -------------------------------------------------------------------------------- 1 | """ 2 | What code to write for Flights problem 3 | - Flight class with properties (only those needed) 4 | - FlightRepository (text-file based directly, no inheritance) 5 | - FlightService 6 | - UserInterface class (implement 1 functionality at a time) 7 | - Print all flights when starting the program 8 | - PyUnit test for add flight functionality 9 | -> class TestAddFlight(TestCase): 10 | ... 11 | 12 | -> specification in Service/Repository classes for addFlight function 13 | what is a function specification?? 14 | - what the function does (in human terms) -> NOT how the function does it 15 | - input parameters 16 | - what it returns (in all cases, so None included) 17 | - any exceptions raised? 18 | 19 | 20 | 21 | 22 | 23 | """ 24 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/domain/recipe.py: -------------------------------------------------------------------------------- 1 | from lecture.livecoding.lecture_9.domain.bakery_object import BakeryObject 2 | from lecture.livecoding.lecture_9.domain.ingredient import Ingredient 3 | 4 | 5 | class Recipe(BakeryObject): 6 | def __init__(self, object_id: int, name: str): 7 | super().__init__(object_id, name) 8 | self.__ingredients = [] 9 | 10 | def add_ingredient(self, ingredient: Ingredient): 11 | self.__ingredients.append(ingredient) 12 | 13 | @property 14 | def ingredients(self): 15 | """ 16 | Returns a reference to the LIVE LIST of ingredients 17 | :return: The list of ingredients 18 | """ 19 | return self.__ingredients 20 | 21 | def __str__(self): 22 | s = f"Recipe {self.id} - {self.name}:\r\n" 23 | for ingr in self.ingredients: 24 | s += str(ingr) + "\r\n" 25 | return s 26 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/flights.txt: -------------------------------------------------------------------------------- 1 | RO650,Cluj,05:45,Bucuresti,06:40 2 | 0B3302,Cluj,07:15,Bucuresti,08:15 3 | SLD322,Timisoara,09:05,Cluj,10:00 4 | RO643,Bucuresti,10:15,Cluj,11:10 5 | RO734,Timisoara,10:45,Iasi,12:25 6 | KL2710,Timisoara,14:25,Bucuresti,15:40 7 | RO745,Cluj,12:50,Iasi,14:05 8 | RO746,Iasi,14:30,Cluj,15:50 9 | RO647,Bucuresti,18:05,Cluj,19:00 10 | KL2706,Bucuresti,18:10,Timisoara,19:05 11 | RO733,Iasi,08:30,Timisoara,10:20 12 | SLD363,Cluj,19:35,Timisoara,20:30 13 | RO649,Bucuresti,21:55,Cluj,22:50 14 | 0B3101,Bucuresti,22:55,Cluj,23:55 15 | RP621,Bucuresti,07:30,Oradea,08:55 16 | RO622,Oradea,09:20,Bucuresti,10:40 17 | RO627,Bucuresti,17:55,Oradea,19:20 18 | RO628,Oradea,19:45,Bucuresti,21:05 19 | XL897,TgMures,08:55,Oradea,09:30 20 | LH012,Iasi,14:35,Oradea,15:35 21 | LH013,Oradea,17:00,Iasi,18:10 22 | RU776,Iasi,12:15,Bacau,12:50 23 | RO111,Cluj,12:50,Paris,13:50 24 | RO333,Sibiu,12:40,Bacau,13:40 25 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/flights.txt: -------------------------------------------------------------------------------- 1 | RO650,Cluj,05:45,Bucuresti,06:40 2 | 0B3302,Cluj,07:15,Bucuresti,08:15 3 | SLD322,Timisoara,09:05,Cluj,10:00 4 | RO643,Bucuresti,10:15,Cluj,11:10 5 | RO734,Timisoara,10:45,Iasi,12:25 6 | KL2710,Timisoara,14:25,Bucuresti,15:40 7 | RO745,Cluj,12:50,Iasi,14:05 8 | RO746,Iasi,14:30,Cluj,15:50 9 | RO647,Bucuresti,18:05,Cluj,19:00 10 | KL2706,Bucuresti,18:10,Timisoara,19:05 11 | RO733,Iasi,08:30,Timisoara,10:20 12 | SLD363,Cluj,19:35,Timisoara,20:30 13 | RO649,Bucuresti,21:55,Cluj,22:50 14 | 0B3101,Bucuresti,22:55,Cluj,23:55 15 | RP621,Bucuresti,07:30,Oradea,08:55 16 | RO622,Oradea,09:20,Bucuresti,10:40 17 | RO627,Bucuresti,17:55,Oradea,19:20 18 | RO628,Oradea,19:45,Bucuresti,21:05 19 | XL897,TgMures,08:55,Oradea,09:30 20 | LH012,Iasi,14:35,Oradea,15:35 21 | LH013,Oradea,17:00,Iasi,18:10 22 | RU776,Iasi,12:15,Bacau,12:50 23 | RO111,Cluj,12:50,Paris,13:50 24 | RO120,Iasi,10:30,Constanta,11:30 25 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/flights.txt: -------------------------------------------------------------------------------- 1 | RO650,Cluj,05:45,Bucuresti,06:40 2 | 0B3302,Cluj,07:15,Bucuresti,08:15 3 | SLD322,Timisoara,09:05,Cluj,10:00 4 | RO643,Bucuresti,10:15,Cluj,11:10 5 | RO734,Timisoara,10:45,Iasi,12:25 6 | KL2710,Timisoara,14:25,Bucuresti,15:40 7 | RO745,Cluj,12:50,Iasi,14:05 8 | RO746,Iasi,14:30,Cluj,15:50 9 | RO647,Bucuresti,18:05,Cluj,19:00 10 | KL2706,Bucuresti,18:10,Timisoara,19:05 11 | RO733,Iasi,08:30,Timisoara,10:20 12 | SLD363,Cluj,19:35,Timisoara,20:30 13 | RO649,Bucuresti,21:55,Cluj,22:50 14 | 0B3101,Bucuresti,22:55,Cluj,23:55 15 | RP621,Bucuresti,07:30,Oradea,08:55 16 | RO622,Oradea,09:20,Bucuresti,10:40 17 | RO627,Bucuresti,17:55,Oradea,19:20 18 | RO628,Oradea,19:45,Bucuresti,21:05 19 | XL897,TgMures,08:55,Oradea,09:30 20 | LH012,Iasi,14:35,Oradea,15:35 21 | LH013,Oradea,17:00,Iasi,18:10 22 | RU776,Iasi,12:15,Bacau,12:50 23 | RO111,Cluj,12:50,Paris,13:50 24 | RO222,Baia Mare,12:30,Brasov,13:30 25 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar12/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | from Seminar917.Seminar12.exceptions import BoardException 4 | 5 | 6 | class ComputerGame: 7 | def __init__(self, ownBoard, opponentBoard): 8 | self.__ownBoard = ownBoard 9 | self.__opponentBoard = opponentBoard 10 | 11 | def placeShip(self): 12 | try: 13 | row = randint(0, self.__ownBoard.size - 1) 14 | column = randint(0, self.__ownBoard.size - 3) 15 | self.__ownBoard.placeShip(row, column) 16 | except BoardException: 17 | self.placeShip() 18 | 19 | def hit(self): 20 | try: 21 | row = randint(0, self.__opponentBoard.size - 1) 22 | column = randint(0, self.__opponentBoard.size - 1) 23 | self.__opponentBoard.hit(row, column) 24 | return row, column 25 | except BoardException: 26 | self.hit() 27 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar12/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | from Seminar916.Seminar12.exceptions import BoardExceptions 4 | 5 | 6 | class ComputerGame: 7 | def __init__(self, ownBoard, opponentBoard): 8 | self.__ownBoard = ownBoard 9 | self.__opponentBoard = opponentBoard 10 | 11 | def placeShip(self): 12 | try: 13 | row = randint(0, self.__ownBoard.size - 1) 14 | column = randint(0, self.__ownBoard.size - 4) 15 | self.__ownBoard.placeShip(row, column) 16 | except BoardExceptions: 17 | self.placeShip() 18 | 19 | def hit(self): 20 | try: 21 | row = randint(0, self.__opponentBoard.size - 1) 22 | column = randint(0, self.__opponentBoard.size - 1) 23 | 24 | self.__opponentBoard.hit(row, column) 25 | return row, column 26 | except BoardExceptions: 27 | self.hit() 28 | 29 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_14/seminar_14.py: -------------------------------------------------------------------------------- 1 | """ 2 | What code to write for Flights problem 3 | - Flight class with properties (only those needed) 4 | - FlightRepository (text-file based directly, no inheritance) 5 | - FlightService 6 | - UserInterface class (implement 1 functionality at a time) 7 | - Print all flights when starting the program 8 | - PyUnit test for add flight functionality 9 | -> class TestAddFlight(TestCase): 10 | ... 11 | 12 | -> specification in Service/Repository classes for addFlight function 13 | what is a function specification?? 14 | - what the function does (in human terms) -> NOT how the function does it 15 | - input parameters 16 | - what it returns (in all cases, so None included) 17 | - any exceptions raised? 18 | 19 | The attached code is a student solution for the problem requirements 20 | """ 21 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_7/game.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_7.board import move_board, get_symbol_board, is_full_board 2 | 3 | 4 | def move_human(board, row: int, col: int) -> None: 5 | """ 6 | Record the human player's move. The human player plays with the 'X' 7 | :param board: The board 8 | :param row: The row and column of the move 9 | :param col: 10 | """ 11 | # Any exceptions raised in move_board will be raised from this method too 12 | move_board(board, 'X', row, col) 13 | 14 | 15 | def move_computer(board) -> None: 16 | if is_full_board(board): 17 | raise ValueError('Computer cannot make a move on a full board') 18 | 19 | for row in (0, 1, 2): 20 | for col in (0, 1, 2): 21 | if get_symbol_board(board, row, col) == '': 22 | move_board(board, 'O', row, col) 23 | # TODO Return the move coordinates to show them to the user 24 | return 25 | -------------------------------------------------------------------------------- /src/lecture/examples/ex03_program_flow.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Sep 23, 2016 3 | 4 | @author: Arthur 5 | """ 6 | 7 | """ 8 | Read a number and check whether it is prime 9 | """ 10 | x = input("Give the number: ") 11 | x = int(x) 12 | 13 | isPrime = True 14 | for i in range(2, x // 2): 15 | if x % i == 0: 16 | isPrime = False 17 | 18 | if isPrime: 19 | print("Number is prime!") 20 | else: 21 | print("Number is not prime!") 22 | 23 | """ 24 | NB! 25 | Let's break program flow as soon as we know it's not a prime 26 | """ 27 | x = input("Give the number: ") 28 | x = int(x) 29 | 30 | isPrime = True 31 | i = 2 32 | while isPrime and i <= x // 2: 33 | i += 1 34 | if x % i == 0: 35 | isPrime = False 36 | 37 | if isPrime: 38 | print("Number is prime!") 39 | else: 40 | print("Number is not prime!") 41 | 42 | """ 43 | Open question! 44 | How can you check the functions above do what they are supposed to? 45 | """ 46 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client: 2 | def __init__(self, clientId, name): 3 | self.__id = clientId 4 | self._name = name 5 | 6 | @property 7 | def id(self): 8 | return self.__id 9 | 10 | @property 11 | def name(self): 12 | return self._name 13 | 14 | @name.setter 15 | def name(self, value): 16 | self._name = value 17 | 18 | def __eq__(self, z): 19 | # don't compare apples to oranges 20 | if type(z) != Client: 21 | return False 22 | # just look at the id field 23 | return self.id == z.id 24 | 25 | def __str__(self): 26 | return f"{self.id} - {self.name}" 27 | 28 | def __repr__(self): 29 | return str(self) 30 | 31 | 32 | if __name__ == "__main__": 33 | c1 = Client(1000, "Popescu Ana") 34 | c2 = Client(1001, "Popescu Ana") 35 | # print(c1 == c2) 36 | # print(repr(c1)) 37 | print({1000: c1, 1001: c2}) -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client(object): 2 | def __init__(self, clientId, name): 3 | self.__id = clientId 4 | self._name = name 5 | 6 | @property 7 | def id(self): 8 | return self.__id 9 | 10 | @property 11 | def name(self): 12 | return self._name 13 | 14 | @name.setter 15 | def name(self, value): 16 | self._name = value 17 | 18 | def __eq__(self, z): 19 | # don't compare apples to oranges 20 | if type(z) != Client: 21 | return False 22 | # just look at the id field 23 | return self.id == z.id 24 | 25 | def __str__(self): 26 | return f"{self.id} - {self.name}" 27 | 28 | def __repr__(self): 29 | return str(self) 30 | 31 | 32 | if __name__ == "__main__": 33 | c1 = Client(1000, "Popescu Ana") 34 | c2 = Client(1001, "Popescu Ana") 35 | # print(c1 == c2) 36 | # print(repr(c1)) 37 | print({1000: c1, 1001: c2}) -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client(object): 2 | def __init__(self, client_id, name): 3 | self.__id = client_id 4 | self._name = name 5 | 6 | @property 7 | def id(self): 8 | return self.__id 9 | 10 | @property 11 | def name(self): 12 | return self._name 13 | 14 | @name.setter 15 | def name(self, value): 16 | self._name = value 17 | 18 | def __eq__(self, z): 19 | # don't compare apples to oranges 20 | if type(z) != Client: 21 | return False 22 | # just look at the id field 23 | return self.id == z.id 24 | 25 | def __str__(self): 26 | return f"{self.id} - {self.name}" 27 | 28 | def __repr__(self): 29 | return str(self) 30 | 31 | 32 | if __name__ == "__main__": 33 | c1 = Client(1000, "Popescu Ana") 34 | c2 = Client(1001, "Popescu Ana") 35 | # print(c1 == c2) 36 | # print(repr(c1)) 37 | print({1000: c1, 1001: c2}) 38 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client(object): 2 | def __init__(self, client_id, name): 3 | self.__id = client_id 4 | self._name = name 5 | 6 | @property 7 | def id(self): 8 | return self.__id 9 | 10 | @property 11 | def name(self): 12 | return self._name 13 | 14 | @name.setter 15 | def name(self, value): 16 | self._name = value 17 | 18 | def __eq__(self, z): 19 | # don't compare apples to oranges 20 | if type(z) != Client: 21 | return False 22 | # just look at the id field 23 | return self.id == z.id 24 | 25 | def __str__(self): 26 | return f"{self.id} - {self.name}" 27 | 28 | def __repr__(self): 29 | return str(self) 30 | 31 | 32 | if __name__ == "__main__": 33 | c1 = Client(1000, "Popescu Ana") 34 | c2 = Client(1001, "Popescu Ana") 35 | # print(c1 == c2) 36 | # print(repr(c1)) 37 | print({1000: c1, 1001: c2}) 38 | -------------------------------------------------------------------------------- /src/lecture/examples/ex30_modular_calc/domain/rational.py: -------------------------------------------------------------------------------- 1 | """ 2 | Utility module to work with rational numbers 3 | """ 4 | from math import gcd 5 | 6 | 7 | def create_rational(nom, den=1): 8 | if den == 0: 9 | raise ValueError("Denominator cannot be 0") 10 | d = gcd(nom, den) 11 | return [nom // d, den // d] 12 | 13 | 14 | def get_numerator(q): 15 | return q[0] 16 | 17 | 18 | def get_denominator(q): 19 | return q[1] 20 | 21 | 22 | def add(q1, q2): 23 | """ 24 | Return the sum of two rational numbers. 25 | q1, q2 the rational numbers 26 | return the sum 27 | """ 28 | return create_rational(get_numerator(q1) * get_denominator(q2) + get_numerator(q2) * get_denominator(q1), get_denominator(q1) * get_denominator(q2)) 29 | 30 | 31 | def test_add(): 32 | """ 33 | Test function for rational_add 34 | """ 35 | assert add(create_rational(1, 2), create_rational(1, 3)) == create_rational(5, 6) 36 | assert add(create_rational(1, 2), create_rational(1, 2)) == create_rational(1) 37 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_13/repository.py: -------------------------------------------------------------------------------- 1 | class Repository: 2 | def __init__(self, filename="sentinces.txt"): 3 | self.__filename = filename 4 | self.__sentinces = [] 5 | self.__load_sentinces() 6 | 7 | def __load_sentinces(self): 8 | with open(self.__filename) as f: 9 | lines = f.readlines() 10 | self.__sentinces = [line.strip() for line in lines] 11 | 12 | def get_sentinces(self): 13 | return self.__sentinces 14 | 15 | def add_sentince(self, sentince): 16 | if sentince in self.__sentinces: 17 | raise ValueError("Sentince already exists") 18 | return 19 | self.__sentinces.append(sentince) 20 | self.__save_sentinces() 21 | 22 | def __save_sentinces(self): 23 | with open(self.__filename, 'w') as f: 24 | for sentince in self.__sentinces: 25 | f.write(sentince + '\n') 26 | 27 | def __len__(self): 28 | return len(self.__sentinces) 29 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar7/ui.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar7.board import createBoard, toString, isBoardWon, isBoardDraw 2 | from Seminar916.Seminar7.game import humanMove, computerMove 3 | 4 | 5 | def start(): 6 | board = createBoard() 7 | humanTurn = True 8 | 9 | while True: 10 | print(toString(board)) 11 | 12 | if humanTurn == True: 13 | try: 14 | x = int(input("x = ")) 15 | y = int(input("y = ")) 16 | humanMove(board, x, y) 17 | except ValueError as ve: 18 | print(ve) 19 | continue 20 | else: 21 | computerMove(board) 22 | 23 | if isBoardWon(board) == True: 24 | if humanTurn == True: 25 | print("Congrats! You have won") 26 | else: 27 | print("The computer has won :(") 28 | break 29 | elif isBoardDraw(board) == True: 30 | print("We have a draw") 31 | 32 | humanTurn = not humanTurn 33 | 34 | start() -------------------------------------------------------------------------------- /src/seminar/group913/seminar_7/game.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | from seminar.group913.seminar_7.board import get_free_squares_board 4 | from seminar.group913.seminar_7.board import move_board 5 | 6 | 7 | # import seminar.group914.seminar_7.board 8 | 9 | 10 | def move_human(board, row: int, col: int) -> None: 11 | move_board(board, 'X', row, col) 12 | 13 | 14 | """ 15 | Each _play_* function implements a computer play algorithm 16 | You can switch how the computer plays by changing the function that is called 17 | Implementation of Strategy Design Pattern 18 | https://refactoring.guru/design-patterns/strategy 19 | """ 20 | 21 | 22 | def _play_random_move(board) -> tuple: 23 | row, col = choice(get_free_squares_board(board)) # tuple unpacking 24 | move_board(board, 'O', row, col) 25 | return row, col 26 | 27 | 28 | def _play_smart_move(board) -> tuple: 29 | # TODO Implement 30 | pass 31 | 32 | 33 | def move_computer(board) -> tuple: 34 | # return _play_random_move(board) 35 | return _play_smart_move() 36 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_7/ui.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_7.board import create_board, to_str, is_won_board, is_full_board 2 | from seminar.group914.seminar_7.game import move_human, move_computer 3 | 4 | 5 | def play(): 6 | board = create_board() 7 | is_player_turn = True 8 | 9 | while True: 10 | print(to_str(board)) 11 | 12 | if is_player_turn: 13 | move_row = int(input("X=")) 14 | move_col = int(input("Y=")) 15 | move_human(board, move_row, move_col) 16 | else: 17 | move_computer(board) 18 | 19 | if is_won_board(board): 20 | if is_player_turn: 21 | print("Congratulations!") 22 | else: 23 | print("Comiserations!") 24 | print(to_str(board)) 25 | break 26 | if is_full_board(board): 27 | print("Game over!") 28 | print(to_str(board)) 29 | break 30 | 31 | is_player_turn = not is_player_turn 32 | 33 | 34 | if __name__ == "__main__": 35 | play() 36 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/domain/rentalValidator.py: -------------------------------------------------------------------------------- 1 | from seminar10.domain.rental import Rental 2 | from datetime import date 3 | 4 | class ValidatorException(Exception): 5 | def __init__(self, message_list="Validation error!"): 6 | self._message_list = message_list 7 | 8 | @property 9 | def messages(self): 10 | return self._message_list 11 | 12 | def __str__(self): 13 | result = "" 14 | for message in self.messages: 15 | result += message 16 | result += "\n" 17 | return result 18 | 19 | class RentalValidator: 20 | def validate(self, rental): 21 | if isinstance(rental, Rental) is False: 22 | raise TypeError("Not a Rental") 23 | 24 | _errorList = [] 25 | now = date(2024, 12, 3) 26 | if rental.start < now: 27 | _errorList.append("Rental starts in past;") 28 | if len(rental) < 5: 29 | _errorList.append("Rental must be at least 5 days;") 30 | if len(_errorList) > 0: 31 | raise ValidatorException(_errorList) -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/domain/rentalValidator.py: -------------------------------------------------------------------------------- 1 | from seminar10.domain.rental import Rental 2 | from datetime import date 3 | 4 | class ValidatorException(Exception): 5 | def __init__(self, message_list="Validation error!"): 6 | self._message_list = message_list 7 | 8 | @property 9 | def messages(self): 10 | return self._message_list 11 | 12 | def __str__(self): 13 | result = "" 14 | for message in self.messages: 15 | result += message 16 | result += "\n" 17 | return result 18 | 19 | class RentalValidator: 20 | def validate(self, rental): 21 | if isinstance(rental, Rental) is False: 22 | raise TypeError("Not a Rental") 23 | 24 | _errorList = [] 25 | now = date(2024, 12, 3) 26 | if rental.start < now: 27 | _errorList.append("Rental starts in past;") 28 | if len(rental) < 5: 29 | _errorList.append("Rental must be at least 5 days;") 30 | if len(_errorList) > 0: 31 | raise ValidatorException(_errorList) -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/domain/rentalValidator.py: -------------------------------------------------------------------------------- 1 | from seminar10.domain.rental import Rental 2 | from datetime import date 3 | 4 | class ValidatorException(Exception): 5 | def __init__(self, message_list="Validation error!"): 6 | self._message_list = message_list 7 | 8 | @property 9 | def messages(self): 10 | return self._message_list 11 | 12 | def __str__(self): 13 | result = "" 14 | for message in self.messages: 15 | result += message 16 | result += "\n" 17 | return result 18 | 19 | class RentalValidator: 20 | def validate(self, rental): 21 | if isinstance(rental, Rental) is False: 22 | raise TypeError("Not a Rental") 23 | 24 | _errorList = [] 25 | now = date(2024, 12, 3) 26 | if rental.start < now: 27 | _errorList.append("Rental starts in past;") 28 | if len(rental) < 5: 29 | _errorList.append("Rental must be at least 5 days;") 30 | if len(_errorList) > 0: 31 | raise ValidatorException(_errorList) -------------------------------------------------------------------------------- /src/seminar/group915/Seminar7/ui.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar7.board import createBoard, toString, isBoardWon, isBoardDraw 2 | from Seminar915.Seminar7.game import humanMove, computerMove 3 | 4 | 5 | def start(): 6 | board = createBoard() 7 | humanTurn = True 8 | 9 | while True: 10 | print(toString(board)) 11 | 12 | if humanTurn == True: 13 | try: 14 | x = int(input("x = ")) 15 | y = int(input("y = ")) 16 | humanMove(board, x, y) 17 | except ValueError as ve: 18 | print(ve) 19 | else: 20 | computerMove(board) 21 | 22 | if isBoardWon(board) == True: 23 | if humanTurn == True: 24 | print("You have won !!!!!!!") 25 | else: 26 | print("The computer has won ! :(") 27 | print(toString(board)) 28 | break 29 | elif isBoardDraw(board) == True: 30 | print("We have a a draw") 31 | break 32 | 33 | humanTurn = not humanTurn 34 | 35 | start() 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/cars.txt: -------------------------------------------------------------------------------- 1 | 1,VS 65 HNV,Dacia,Logan,blue 2 | 2,TL 51 QQP,Dacia,Lodgy,red 3 | 3,IS 97 EJG,Toyota,Yaris,red 4 | 4,TR 91 KTU,Dacia,Sandero,blue 5 | 5,TL 89 SSI,Dacia,Sandero,black 6 | 6,TL 23 LTR,Dacia,Sandero,green 7 | 7,TR 24 UVD,Toyota,RAV-4,red 8 | 8,CJ 92 TRD,Dacia,Logan,green 9 | 9,CJ 36 ZIA,Dacia,Logan,red 10 | 10,IS 66 DJX,Dacia,Sandero,blue 11 | 11,CJ 51 HCN,Dacia,Lodgy,red 12 | 12,VS 23 GWQ,Toyota,Yaris,red 13 | 13,IS 59 WCC,Toyota,Corolla,red 14 | 14,CJ 92 YDU,Toyota,Yaris,green 15 | 15,AB 19 FIN,Dacia,Lodgy,blue 16 | 16,TL 70 GYH,Toyota,Corolla,red 17 | 17,TR 64 QBZ,Dacia,Logan,blue 18 | 18,TL 79 NEB,Dacia,Logan,black 19 | 19,GL 42 RKZ,Dacia,Lodgy,green 20 | 20,CJ 56 KNZ,Toyota,RAV-4,green 21 | 21,GR 29 DUQ,Toyota,RAV-4,green 22 | 22,AB 65 OJD,Dacia,Sandero,red 23 | 23,TL 53 KYY,Dacia,Lodgy,green 24 | 24,GL 58 ETL,Dacia,Logan,black 25 | 25,IS 73 YZI,Dacia,Lodgy,black 26 | 26,IS 61 VWR,Dacia,Sandero,green 27 | 27,CJ 57 FTB,Toyota,Corolla,black 28 | 28,B 36 VEF,Toyota,Yaris,blue 29 | 29,GR 17 ERN,Toyota,RAV-4,green 30 | 30,AB 40 ZXT,Dacia,Sandero,green 31 | 99,BN 99 USB,Dacia,Sandero,pink 32 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/cars.txt: -------------------------------------------------------------------------------- 1 | 1,VS 65 HNV,Dacia,Logan,blue 2 | 2,TL 51 QQP,Dacia,Lodgy,red 3 | 3,IS 97 EJG,Toyota,Yaris,red 4 | 4,TR 91 KTU,Dacia,Sandero,blue 5 | 5,TL 89 SSI,Dacia,Sandero,black 6 | 6,TL 23 LTR,Dacia,Sandero,green 7 | 7,TR 24 UVD,Toyota,RAV-4,red 8 | 8,CJ 92 TRD,Dacia,Logan,green 9 | 9,CJ 36 ZIA,Dacia,Logan,red 10 | 10,IS 66 DJX,Dacia,Sandero,blue 11 | 11,CJ 51 HCN,Dacia,Lodgy,red 12 | 12,VS 23 GWQ,Toyota,Yaris,red 13 | 13,IS 59 WCC,Toyota,Corolla,red 14 | 14,CJ 92 YDU,Toyota,Yaris,green 15 | 15,AB 19 FIN,Dacia,Lodgy,blue 16 | 16,TL 70 GYH,Toyota,Corolla,red 17 | 17,TR 64 QBZ,Dacia,Logan,blue 18 | 18,TL 79 NEB,Dacia,Logan,black 19 | 19,GL 42 RKZ,Dacia,Lodgy,green 20 | 20,CJ 56 KNZ,Toyota,RAV-4,green 21 | 21,GR 29 DUQ,Toyota,RAV-4,green 22 | 22,AB 65 OJD,Dacia,Sandero,red 23 | 23,TL 53 KYY,Dacia,Lodgy,green 24 | 24,GL 58 ETL,Dacia,Logan,black 25 | 25,IS 73 YZI,Dacia,Lodgy,black 26 | 26,IS 61 VWR,Dacia,Sandero,green 27 | 27,CJ 57 FTB,Toyota,Corolla,black 28 | 28,B 36 VEF,Toyota,Yaris,blue 29 | 29,GR 17 ERN,Toyota,RAV-4,green 30 | 30,AB 40 ZXT,Dacia,Sandero,green 31 | 99,BN 99 USB,Dacia,Sandero,pink 32 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/cars.txt: -------------------------------------------------------------------------------- 1 | 1,VS 65 HNV,Dacia,Logan,blue 2 | 2,TL 51 QQP,Dacia,Lodgy,red 3 | 3,IS 97 EJG,Toyota,Yaris,red 4 | 4,TR 91 KTU,Dacia,Sandero,blue 5 | 5,TL 89 SSI,Dacia,Sandero,black 6 | 6,TL 23 LTR,Dacia,Sandero,green 7 | 7,TR 24 UVD,Toyota,RAV-4,red 8 | 8,CJ 92 TRD,Dacia,Logan,green 9 | 9,CJ 36 ZIA,Dacia,Logan,red 10 | 10,IS 66 DJX,Dacia,Sandero,blue 11 | 11,CJ 51 HCN,Dacia,Lodgy,red 12 | 12,VS 23 GWQ,Toyota,Yaris,red 13 | 13,IS 59 WCC,Toyota,Corolla,red 14 | 14,CJ 92 YDU,Toyota,Yaris,green 15 | 15,AB 19 FIN,Dacia,Lodgy,blue 16 | 16,TL 70 GYH,Toyota,Corolla,red 17 | 17,TR 64 QBZ,Dacia,Logan,blue 18 | 18,TL 79 NEB,Dacia,Logan,black 19 | 19,GL 42 RKZ,Dacia,Lodgy,green 20 | 20,CJ 56 KNZ,Toyota,RAV-4,green 21 | 21,GR 29 DUQ,Toyota,RAV-4,green 22 | 22,AB 65 OJD,Dacia,Sandero,red 23 | 23,TL 53 KYY,Dacia,Lodgy,green 24 | 24,GL 58 ETL,Dacia,Logan,black 25 | 25,IS 73 YZI,Dacia,Lodgy,black 26 | 26,IS 61 VWR,Dacia,Sandero,green 27 | 27,CJ 57 FTB,Toyota,Corolla,black 28 | 28,B 36 VEF,Toyota,Yaris,blue 29 | 29,GR 17 ERN,Toyota,RAV-4,green 30 | 30,AB 40 ZXT,Dacia,Sandero,green 31 | 99,BN 99 USB,Dacia,Sandero,pink 32 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_7/rational_as_list.py: -------------------------------------------------------------------------------- 1 | from math import gcd 2 | 3 | 4 | def create_rational(num: int, denom: int = 1): 5 | """ 6 | Create a rational number 7 | :param num: numerator 8 | :param denom: non-zero denominator 9 | :return: the created number 10 | 11 | :raises: Raises ValueError in case the denom is 0 12 | """ 13 | if denom == 0: 14 | raise ValueError("Denominator must be non-0") 15 | 16 | _gcd = gcd(num, denom) 17 | return [num // _gcd, denom // _gcd] 18 | 19 | 20 | def get_numerator(q) -> int: 21 | return q[0] 22 | 23 | 24 | def get_denominator(q) -> int: 25 | return q[1] 26 | 27 | 28 | def to_str(q) -> str: 29 | # TODO fix 1/-2, 5/-1 etc. 30 | if get_denominator(q) == 1: 31 | return str(get_numerator(q)) 32 | return str(get_numerator(q)) + "/" + str(get_denominator(q)) 33 | 34 | 35 | def add_rational(q1, q2): 36 | gn = get_numerator # () -- function call operator 37 | gd = get_denominator 38 | num = gn(q1) * gd(q2) + gn(q2) * gd(q1) 39 | denom = gd(q1) * gd(q2) 40 | return create_rational(num, denom) 41 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_8/ui.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_8.game import Game 2 | 3 | 4 | class UI: 5 | def __init__(self): 6 | self.__game = Game() 7 | 8 | def play(self): 9 | is_player_turn = True 10 | board = self.__game.get_board() 11 | while True: 12 | print(board) 13 | 14 | if is_player_turn: 15 | move_row = int(input("X=")) 16 | move_col = int(input("Y=")) 17 | self.__game.move_human(move_row, move_col) 18 | else: 19 | self.__game.move_computer() 20 | 21 | if board.is_won(): 22 | if is_player_turn: 23 | print("Congratulations!") 24 | else: 25 | print("Comiserations!") 26 | print(board) 27 | break 28 | if board.is_full(): 29 | print("Game over!") 30 | print(board) 31 | break 32 | 33 | is_player_turn = not is_player_turn 34 | 35 | 36 | if __name__ == "__main__": 37 | ui = UI() 38 | ui.play() 39 | -------------------------------------------------------------------------------- /src/lecture/examples/ex36_rational_calc/calculator.py: -------------------------------------------------------------------------------- 1 | from lecture.examples.ex36_rational_calc.domain import Rational 2 | 3 | 4 | class Calculator: 5 | def __init__(self): 6 | self._total = Rational(0) 7 | self._history = [] 8 | 9 | @property 10 | def total(self): 11 | # Total is a read-only property 12 | return self._total 13 | 14 | def add(self, r): 15 | """ 16 | Add a number to the calculator. Adding 0 will not create an undo point 17 | param: 18 | r - the number to add 19 | """ 20 | if r == Rational(0): 21 | return 22 | # Record for undo 23 | self._history.append(self._total) 24 | # Add the value to calculator total 25 | self._total += r 26 | 27 | def undo(self): 28 | if len(self._history) == 0: 29 | raise ValueError('No more undo steps!') 30 | self._total = self._history.pop() 31 | 32 | @staticmethod 33 | def get_number_count(): 34 | return Rational.get_total_number_of_instances() 35 | 36 | def reset(self): 37 | self._total = Rational(0) 38 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar14/domain/flight.py: -------------------------------------------------------------------------------- 1 | from datetime import time 2 | 3 | class Flight: 4 | def __init__(self, identifier: str, departureCity: str, departureTime: time, arrivalCity: str, arrivalTime: time): 5 | self.__identifier = identifier 6 | self.__departureCity = departureCity 7 | self.__departureTime = departureTime 8 | self.__arrivalCity = arrivalCity 9 | self.__arrivalTime = arrivalTime 10 | 11 | @property 12 | def identifier(self): 13 | return self.__identifier 14 | 15 | @property 16 | def departureCity(self): 17 | return self.__departureCity 18 | 19 | @property 20 | def departureTime(self): 21 | return self.__departureTime 22 | 23 | @property 24 | def arrivalCity(self): 25 | return self.__arrivalCity 26 | 27 | @property 28 | def arrivalTime(self): 29 | return self.__arrivalTime 30 | 31 | def __str__(self): 32 | return "Flight number " + self.identifier + " departs from " + self.departureCity + " at " + str(self.departureTime) + ", arrives at " + self.arrivalCity + " at " + str(self.arrivalTime) 33 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_13/repository.py: -------------------------------------------------------------------------------- 1 | from domain import Sentence 2 | 3 | class Repository: 4 | def __init__(self, file_name="sentences.txt"): 5 | self.__data=[] 6 | self.__file_name=file_name 7 | self.__load() 8 | 9 | def add(self, sentence:Sentence): 10 | self.__data.append(sentence) 11 | self.__save() 12 | 13 | def __iter__(self): 14 | return iter(self.__data) 15 | 16 | def get_all(self): 17 | return self.__data 18 | 19 | def __load(self): 20 | try: 21 | fin=open(self.__file_name,"rt") 22 | lines=fin.readlines() 23 | for line in lines: 24 | if line.strip(): 25 | sentence=line.strip() 26 | sentence_to_put=Sentence(sentence) 27 | self.__data.append(sentence_to_put) 28 | fin.close() 29 | except FileNotFoundError: 30 | pass 31 | 32 | def __save(self): 33 | fout=open(self.__file_name,"wt") 34 | for sentence in self.__data: 35 | fout.write(sentence.sentence+"\n"+"\n") 36 | fout.close() 37 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar14/domain/flight.py: -------------------------------------------------------------------------------- 1 | from datetime import time 2 | 3 | class Flight: 4 | def __init__(self, identifier: str, departureCity: str, departureTime: time, arrivalCity: str, arrivalTime: time): 5 | self.__identifier = identifier 6 | self.__departureCity = departureCity 7 | self.__departureTime = departureTime 8 | self.__arrivalCity = arrivalCity 9 | self.__arrivalTime = arrivalTime 10 | 11 | @property 12 | def identifier(self): 13 | return self.__identifier 14 | 15 | @property 16 | def departureCity(self): 17 | return self.__departureCity 18 | 19 | @property 20 | def departureTime(self): 21 | return self.__departureTime 22 | 23 | @property 24 | def arrivalCity(self): 25 | return self.__arrivalCity 26 | 27 | @property 28 | def arrivalTime(self): 29 | return self.__arrivalTime 30 | 31 | def __str__(self): 32 | return "Flight number " + self.identifier + " departs from " + self.departureCity + " at " + str(self.departureTime) + ", arrives at " + self.arrivalCity + " at " + str(self.arrivalTime) 33 | 34 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar7/ui.py: -------------------------------------------------------------------------------- 1 | from Seminar917.Seminar7.board import createBoard, toString, isBoardWon, isBoardDraw 2 | from Seminar917.Seminar7.game import humanMove, computerMove 3 | 4 | 5 | def start(): 6 | board = createBoard() 7 | humanTurn = True 8 | 9 | while True: 10 | print(toString(board)) 11 | 12 | if humanTurn == True: 13 | try: 14 | x = int(input("x = ")) 15 | y = int(input("y = ")) 16 | humanMove(board, x, y) 17 | except ValueError as ve: 18 | print(ve) 19 | continue 20 | else: 21 | computerMove(board) 22 | 23 | if isBoardWon(board) == True: 24 | if humanTurn == True: 25 | print("Congrats! You won !!!") 26 | print(toString(board)) 27 | else: 28 | print("The computer has won! :(") 29 | print(toString(board)) 30 | break 31 | elif isBoardDraw(board) == True: 32 | print("We have a draw!!!!") 33 | break 34 | 35 | humanTurn = not humanTurn 36 | 37 | start() -------------------------------------------------------------------------------- /src/seminar/group915/Seminar8/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class ComputerFirstPositionStrategy: 4 | def __init__(self, board): 5 | self.__board = board 6 | 7 | def getNextComputerMove(self): 8 | for i in range(3): 9 | for j in range(3): 10 | if self.__board.getBoard(i, j) == 0: 11 | return i, j 12 | 13 | return -1, -1 14 | 15 | class ComputerRandomStrategy: 16 | def __init__(self, board): 17 | self.__board = board 18 | 19 | def getNextComputerMove(self): 20 | found = False 21 | while not found: 22 | x = randint(0, 2) 23 | y = randint(0, 2) 24 | 25 | if self.__board.getBoard(x, y) == 0: 26 | return x, y 27 | 28 | class Game: 29 | def __init__(self, board, computerStrategy): 30 | self.__board = board 31 | self.__computerStrategy = computerStrategy 32 | 33 | def humanMove(self, x: int, y: int): 34 | self.__board.moveBoard(x, y, 'X') 35 | 36 | def computerMove(self): 37 | x, y = self.__computerStrategy.getNextComputerMove() 38 | self.__board.moveBoard(x, y, 'O') -------------------------------------------------------------------------------- /src/seminar/group914/seminar_8/game.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_8.board import Board 2 | 3 | 4 | class Game: 5 | def __init__(self): 6 | self.__board = Board() 7 | 8 | def get_board(self) -> Board: 9 | return self.__board 10 | 11 | def move_human(self, row: int, col: int) -> None: 12 | """ 13 | Record the human player's move. The human player plays with the 'X' 14 | :param board: The board 15 | :param row: The row and column of the move 16 | :param col: 17 | """ 18 | # Any exceptions raised in move_board will be raised from this method too 19 | self.__board.move('X', row, col) 20 | # move_board(board, 'X', row, col) 21 | 22 | def move_computer(self) -> None: 23 | if self.__board.is_full(): 24 | raise ValueError('Computer cannot make a move on a full board') 25 | 26 | for row in (0, 1, 2): 27 | for col in (0, 1, 2): 28 | if self.__board.get_symbol(row, col) == '': 29 | self.__board.move('O', row, col) 30 | # TODO Return the move coordinates to show them to the user 31 | return 32 | -------------------------------------------------------------------------------- /src/lecture/examples/ex12_stable_sort.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | 4 | def create_person(name: str, age: int): 5 | return {"name": name, "age": age} 6 | 7 | 8 | def get_name(person: dict): 9 | return person["name"] 10 | 11 | 12 | def get_age(person: dict): 13 | return person["age"] 14 | 15 | 16 | def generate(): 17 | """ 18 | Generate some persons 19 | """ 20 | result = [] 21 | 22 | family_name = ['Popescu', 'Marian', 'Pop', 'Lazarescu', 'Dincu'] 23 | given_name = ['Anca', 'Emilia', 'Liviu', 'Marius'] 24 | age = [17, 18, 19, 20] 25 | 26 | for i in range(20): 27 | result.append(create_person(choice(family_name) + " " + choice(given_name), choice(age))) 28 | return result 29 | 30 | 31 | ''' 32 | 1. Generate people 33 | ''' 34 | result = generate() 35 | 36 | ''' 37 | 2. First we sort the list by name (ascending) 38 | ''' 39 | result.sort(key=lambda person: person["name"]) 40 | 41 | ''' 42 | 3. Then we sort by age (descending) - the sorts are STABLE 43 | ''' 44 | result.sort(key=lambda person: person["age"], reverse=True) 45 | 46 | ''' 47 | 4. People of the same age are ordered by name 48 | ''' 49 | for p in result: 50 | print(p) 51 | -------------------------------------------------------------------------------- /src/lecture/examples/ex35_instance_vs_class_fields.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Nov 2, 2016 3 | 4 | @author: Arthur 5 | """ 6 | 7 | 8 | class Student: 9 | # Class field is shared by all instances 10 | __studentCount = 0 11 | 12 | def __init__(self, name="Anonymous"): 13 | self.__name = name 14 | 15 | ''' 16 | NB! 17 | Make sure to prefix the attribute name with: 18 | - class name, or 19 | - type(self) 20 | ''' 21 | Student.__studentCount += 1 22 | 23 | def set_name(self, name): 24 | self.__name = name 25 | 26 | def get_name(self): 27 | return self.__name 28 | 29 | @staticmethod 30 | def get_student_count(): 31 | return Student.__studentCount 32 | 33 | 34 | if __name__ == "__main__": 35 | ''' 36 | We create some students 37 | ''' 38 | s1 = Student() 39 | s2 = Student() 40 | 41 | s1.set_name("Anna") 42 | s2.set_name("Carla") 43 | 44 | print(s1.get_name()) 45 | print(s2.get_name()) 46 | 47 | print(Student.get_student_count()) 48 | 49 | ''' 50 | What happens here? 51 | ''' 52 | # print(student.__studentCount) 53 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_9/ui/ui.py: -------------------------------------------------------------------------------- 1 | from lecture.livecoding.lecture_9.services.services import IngredientService, RecipeService, BakeryProductService 2 | 3 | 4 | class UserInterface: 5 | def __init__(self, ingredient_service: IngredientService, recipe_service: RecipeService, 6 | product_service: BakeryProductService): 7 | # NOTE - The user interface depends on the the services for ingredient, recipe, product 8 | # By providing the required objects as parameters to the constructor, we make sure that 9 | # we cannot build a UserInterface object without all its dependencies 10 | 11 | # NOTE Passing dependencies as constructor parameters is a basic means of dependency injection 12 | # 'dependency injection' - we inject the classes we need through the __init__ call 13 | # NOTE We should be able to change the dependencies without altering the code of the UI class 14 | self.__ingredient_service = ingredient_service 15 | self.__recipe_service = recipe_service 16 | self.__product_service = product_service 17 | 18 | def start_ui(self): 19 | # NOTE This is where we start the program's user interface 20 | pass 21 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar8/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class ComputerFirstAvailablePosStrategy: 4 | def __init__(self, board): 5 | self.__board = board 6 | 7 | def getNextComputerMove(self): 8 | for i in range(3): 9 | for j in range(3): 10 | if self.__board.getBoardValue(i, j) == 0: 11 | return i, j 12 | 13 | return -1, -1 14 | 15 | class ComputerRandomStrategy: 16 | def __init__(self, board): 17 | self.__board = board 18 | 19 | def getNextComputerMove(self): 20 | found = False 21 | while not found: 22 | x = randint(0, 2) 23 | y = randint(0, 2) 24 | if self.__board.getBoardValue(x, y) == 0: 25 | return x, y 26 | 27 | class ComputerBlockingStrategy: 28 | pass 29 | 30 | class Game: 31 | def __init__(self, board, computerStrategy): 32 | self.__board = board 33 | self.__computerStrategy = computerStrategy 34 | 35 | def humanMove(self, x: int, y: int): 36 | self.__board.moveBoard(x, y, 'X') 37 | 38 | def computerMove(self): 39 | x, y = self.__computerStrategy.getNextComputerMove() 40 | self.__board.moveBoard(x, y, 'O') -------------------------------------------------------------------------------- /src/seminar/group913/seminar_14/tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import os 3 | 4 | from repository import FlightRepo 5 | from services import FlightServices 6 | from domain import Flight 7 | 8 | class Tests(unittest.TestCase): 9 | def test_add_flight(self): 10 | ''' 11 | tetst the add_flight method from the services 12 | ''' 13 | test_file_path = os.path.join(os.path.dirname(__file__), "test_flights.txt") 14 | repo = FlightRepo(test_file_path) 15 | services = FlightServices(repo) 16 | services.add_flight(Flight("1", "a", "10:00", "b", "10:45")) 17 | self.assertEqual(len(services.get_all_flights()), 1) 18 | services.add_flight(Flight("2", "b", "12:20", "c", "12:40")) 19 | self.assertEqual(len(services.get_all_flights()), 2) 20 | try: 21 | services.add_flight(Flight("1", "c", "10:50", "d", "10:60")) 22 | assert False 23 | except ValueError: 24 | assert True 25 | 26 | try: 27 | services.add_flight(Flight("3", "a", "10:00", "b", "10:05")) 28 | assert False 29 | except ValueError: 30 | assert True 31 | self.assertEqual(len(services.get_all_flights()), 2) -------------------------------------------------------------------------------- /src/seminar/group913/seminar_7/ui.py: -------------------------------------------------------------------------------- 1 | from seminar.group913.seminar_7.board import create_board, to_str_board, is_won_board, is_full_board 2 | from seminar.group913.seminar_7.game import move_human, move_computer 3 | 4 | 5 | def play(): 6 | board = create_board() 7 | is_players_turn = True 8 | print(to_str_board(board)) 9 | 10 | while not (is_won_board(board) or is_full_board(board)): 11 | if is_players_turn: 12 | try: 13 | row = int(input("X=")) 14 | col = int(input("Y=")) 15 | move_human(board, row, col) 16 | except ValueError as ve: 17 | print(ve) 18 | is_players_turn = not is_players_turn 19 | else: 20 | row, col = move_computer(board) 21 | print(f"Computer played at ({row},{col})") 22 | print(to_str_board(board)) 23 | is_players_turn = not is_players_turn 24 | 25 | # FIXME ! 26 | if is_full_board(board): 27 | print("Game over. It's a draw!") 28 | 29 | if is_won_board(board): 30 | if is_players_turn: 31 | print("Game over. Computer wins") 32 | else: 33 | print("Congrats!") 34 | print(to_str_board(board)) 35 | 36 | 37 | play() 38 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar8/game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class ComputerFirstAvailablePosStrategy: 4 | def __init__(self, board): 5 | self.__board = board 6 | 7 | def getNextComputerMove(self): 8 | for i in range(3): 9 | for j in range(3): 10 | if self.__board.getBoardValue(i, j) == 0: 11 | return i, j 12 | 13 | return -1, -1 14 | 15 | class ComputerRandomStrategy: 16 | def __init__(self, board): 17 | self.__board = board 18 | 19 | def getNextComputerMove(self): 20 | found = False 21 | 22 | while not found: 23 | x = randint(0, 2) 24 | y = randint(0, 2) 25 | 26 | if self.__board.getBoardValue(x, y) == 0: 27 | return x, y 28 | 29 | class ComputerBlockingStrategy: 30 | def __init__(self): 31 | pass 32 | 33 | class Game: 34 | def __init__(self, board, computerStrategy): 35 | self.__board = board 36 | self.__computerStrategy = computerStrategy 37 | 38 | def humanMove(self, x: int, y: int): 39 | self.__board.moveBoard(x, y, 'X') 40 | 41 | def computerMove(self): 42 | x, y = self.__computerStrategy.getNextComputerMove() 43 | self.__board.moveBoard(x, y, 'O') -------------------------------------------------------------------------------- /src/lecture/examples/ex02_basic_compound_types.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Sep 26, 2016 3 | 4 | @author: Arthur 5 | """ 6 | 7 | """ 8 | List 9 | """ 10 | 11 | myList = [1, 2, 3] 12 | print(myList) 13 | 14 | print(myList[1]) 15 | 16 | print('The list has', len(myList), 'elements') 17 | print('Tha first element is', myList[0], 'and the last one is', myList[len(myList) - 1]) 18 | 19 | x = myList 20 | print(myList, x) 21 | 22 | """ 23 | What happens here? 24 | """ 25 | x[1] = '?' 26 | print(myList, x) 27 | 28 | """ 29 | List slicing 30 | """ 31 | myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 32 | print(myList[:2]) 33 | print(myList[2:]) 34 | myList[5:] = ['a', 'b', 'c'] 35 | print(myList) 36 | 37 | myList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 38 | myList[1:9] = 'x' 39 | print(myList) 40 | 41 | """ 42 | Tuple 43 | """ 44 | tup = 1, 2, 'a' 45 | print(tup) 46 | print(tup[1]) 47 | 48 | for e in tup: 49 | print(e) 50 | 51 | """ 52 | What happens if we uncomment this line? 53 | """ 54 | # tup[1] = 'x' 55 | 56 | """ 57 | Dictionary 58 | """ 59 | d = {'num': 1, 'den': 2} 60 | print(d) 61 | 62 | print(d['num']) 63 | d['num'] = 99 64 | print(d['num']) 65 | 66 | if 'num' in d: 67 | print('We have num!') 68 | 69 | del d['num'] 70 | 71 | if 'num' in d: 72 | print('We have num!') 73 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_9/domain/car.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | # class names should start with uppercase letter 3 | def __init__(self, car_id: int, license_plate: str, model: str): 4 | self.__id = car_id 5 | self.__license_plate = license_plate 6 | self.__model = model 7 | 8 | # let's use properties as setters/getters 9 | # suppose we want to read the id but we don't want to change it 10 | # => in this case we make a read-only property 11 | 12 | @property 13 | def id(self): 14 | return self.__id 15 | 16 | @property 17 | def license(self): 18 | return self.__license_plate 19 | 20 | @property 21 | def model(self): 22 | return self.__model 23 | 24 | @model.setter 25 | def model(self, new_value: str): 26 | self.__model = new_value 27 | 28 | def __repr__(self): 29 | return str(self) 30 | 31 | def __str__(self): 32 | return f"{self.id} - {self.license} - {self.model}" 33 | 34 | 35 | def test_car(): 36 | new_car = Car(100, "CJ 01 ABC", "Dacia Sandero") 37 | assert new_car.id == "CJ 01 ABC" 38 | assert new_car.model == "Dacia Sandero" 39 | 40 | 41 | if __name__ == "__main__": 42 | cary = Car(100, "CJ 99 ABC", "Toyota Supra") 43 | print(cary) 44 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_9/domain/car.py: -------------------------------------------------------------------------------- 1 | class Car(object): 2 | # class names should start with uppercase letter 3 | def __init__(self, car_id: int, license_plate: str, model: str): 4 | self.__id = car_id 5 | self.__license_plate = license_plate 6 | self.__model = model 7 | 8 | # let's use properties as setters/getters 9 | # suppose we want to read the id but we don't want to change it 10 | # => in this case we make a read-only property 11 | 12 | @property 13 | def id(self): 14 | return self.__id 15 | 16 | @property 17 | def license(self): 18 | return self.__license_plate 19 | 20 | @property 21 | def model(self): 22 | return self.__model 23 | 24 | @model.setter 25 | def model(self, new_value: str): 26 | self.__model = new_value 27 | 28 | def __repr__(self): 29 | return str(self) 30 | 31 | def __str__(self): 32 | return f"{self.id} - {self.license} - {self.model}" 33 | 34 | 35 | def test_car(): 36 | new_car = Car(100, "CJ 01 ABC", "Dacia Sandero") 37 | assert new_car.id == "CJ 01 ABC" 38 | assert new_car.model == "Dacia Sandero" 39 | 40 | 41 | if __name__ == "__main__": 42 | cary = Car(100, "CJ 99 ABC", "Toyota Supra") 43 | print(cary) 44 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar9/repository/carRepositoryBinary.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | 3 | from Seminar917.Seminar9.domain.car import Car 4 | from Seminar917.Seminar9.repository.carRepositoryInMemory import CarRepositoryInMemory, RepositoryError 5 | 6 | 7 | class CarRepositoryBinary(CarRepositoryInMemory): 8 | def __init__(self, filename): 9 | CarRepositoryInMemory.__init__(self) 10 | #super().__init__() 11 | self.__filename = filename 12 | try: 13 | self.__loadData() 14 | except FileNotFoundError: 15 | raise RepositoryError("File was not found") 16 | except Exception: 17 | raise RepositoryError("Something went terribly wrong") 18 | 19 | def __loadData(self): 20 | file = open(self.__filename, "rb") # r - reading, b - binary 21 | self._data = pickle.load(file) 22 | file.close() 23 | 24 | def __saveData(self): 25 | file = open(self.__filename, "wb") # w - write, b - binary 26 | pickle.dump(self._data, file) 27 | file.close() 28 | 29 | def addCar(self, car: Car): 30 | super().addCar(car) 31 | self.__saveData() 32 | 33 | def removeCar(self, licensePlate: str) -> Car: 34 | super().removeCar(licensePlate) 35 | self.__saveData() 36 | 37 | -------------------------------------------------------------------------------- /src/lecture/examples/ex32_python_class_particularities.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Nov 1, 2016 3 | 4 | @author: Arthur 5 | """ 6 | 7 | 8 | class FirstClass: 9 | pass 10 | 11 | 12 | class SecondClass: 13 | def __init__(self): 14 | self.test_one = "Test One" 15 | self._test_two = "Test Two" 16 | self.__test_three = "Test Three" 17 | 18 | 19 | x = FirstClass() 20 | 21 | ''' 22 | What is the type of x ? 23 | ''' 24 | print(type(x)) 25 | 26 | ''' 27 | An empty class, such as FirstClass can be used as a Pascal record or a C struct 28 | ''' 29 | x.name = "Alice" 30 | x.salary = 100 31 | x.salary += 20 32 | print("Name of x=", x.name) 33 | print("Salary of x=", x.salary) 34 | 35 | y = FirstClass() 36 | y.name = "Bob" 37 | y.salary = 1000 38 | print("Name of y=", y.name) 39 | print("Salary of y=", y.salary) 40 | 41 | ''' 42 | What happens if we add another field on-the-fly? 43 | ''' 44 | y.hello = "Say hello" 45 | print(y.hello) 46 | # Field 'hello' is not a part of instance 'x' 47 | # print(x.hello) 48 | 49 | ''' 50 | How about the more complex, SecondClass example? 51 | ''' 52 | obj = SecondClass() 53 | print(obj.test_one) 54 | # print(obj._test_two) 55 | 56 | ''' 57 | This is Python's name mangling at work 58 | ''' 59 | # print(obj.__test_three) 60 | # print(obj._SecondClass__test_three) 61 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/repository/carRepositoryBinary.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | 3 | from Seminar915.Seminar9.repository.carsRepositoryInMemory import RepositoryError 4 | from Seminar916.Seminar9.domain.car import Car 5 | from Seminar916.Seminar9.repository.carRepositoryInMemory import CarRepositoryInMemory 6 | 7 | 8 | class CarRepositoryBinary(CarRepositoryInMemory): 9 | def __init__(self, filename): 10 | CarRepositoryInMemory.__init__(self) 11 | #super().__init__() 12 | self.__filename = filename 13 | try: 14 | self.__loadData() 15 | except FileNotFoundError: 16 | raise RepositoryError("File was not found") 17 | except Exception: 18 | raise RepositoryError("Something went wrong") 19 | 20 | def __loadData(self): 21 | file = open(self.__filename, "rb") # r - read, b - binary 22 | self._data = pickle.load(file) 23 | file.close() 24 | 25 | def __saveData(self): 26 | file = open(self.__filename, "wb") # w - write, b - binary 27 | pickle.dump(self._data, file) 28 | file.close() 29 | 30 | def addCar(self, car: Car): 31 | super().addCar(car) 32 | self.__saveData() 33 | 34 | def removeCar(self, licensePlate: str) -> Car: 35 | super().removeCar(licensePlate) 36 | self.__saveData() -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/service/car_service.py: -------------------------------------------------------------------------------- 1 | from seminar.group914.seminar_11.domain.car import Car 2 | 3 | 4 | class CarService: 5 | def __init__(self, undo_service, rental_service, validator, repository): 6 | self._validator = validator 7 | self._repository = repository 8 | self._rental_service = rental_service 9 | self._undo_service = undo_service 10 | 11 | def create(self, car_id, license_plate, car_make, car_model): 12 | car = Car(car_id, license_plate, car_make, car_model) 13 | self._validator.validate(car) 14 | self._repository.store(car) 15 | return car 16 | 17 | def delete(self, car_id): 18 | """ 19 | 1. Delete the car from the repository 20 | """ 21 | car = self._repository.delete(car_id) 22 | 23 | ''' 24 | 2. Delete its rentals 25 | NB! This implementation is not transactional, i.e. the two delete operations are performed separately 26 | ''' 27 | rentals = self._rental_service.filter_rentals(None, car) 28 | for rent in rentals: 29 | self._rental_service.delete_rental(rent.id) 30 | return car 31 | 32 | def update(self, car): 33 | """ 34 | NB! Undo/redo is also needed here 35 | """ 36 | # TODO Implement later... 37 | pass 38 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/repository/carsRepositoryBinary.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar9.domain.car import Car 2 | from Seminar915.Seminar9.repository.carsRepositoryInMemory import CarRepositoryInMemory 3 | import pickle 4 | 5 | from seminar9.repository.repository import RepositoryError 6 | 7 | 8 | class CarRepositoryBinary(CarRepositoryInMemory): 9 | def __init__(self, filename): 10 | CarRepositoryInMemory.__init__(self) 11 | #super().__init__() 12 | self.__filename = filename 13 | try: 14 | self.__loadFile() 15 | except FileNotFoundError: 16 | raise RepositoryError("The specified binary file was not found") 17 | except Exception: 18 | raise RepositoryError("Something went wrong") 19 | 20 | 21 | def __saveFile(self): 22 | file = open(self.__filename, "wb") # w - write, b - binary 23 | pickle.dump(self._data, file) 24 | file.close() 25 | 26 | def __loadFile(self): 27 | file = open(self.__filename, "rb") # r - read, b - binary 28 | self._data = pickle.load(file) 29 | file.close() 30 | 31 | def addCar(self, car: Car): 32 | super().addCar(car) 33 | self.__saveFile() 34 | 35 | def removeCar(self, licensePlate: str) -> Car: 36 | car = super().removeCar(licensePlate) 37 | self.__saveFile() 38 | return car -------------------------------------------------------------------------------- /src/seminar/group915/Seminar14/domain/flight.py: -------------------------------------------------------------------------------- 1 | from datetime import time 2 | 3 | class Flight: 4 | def __init__(self, identifier: str, departureCity: str, departureTime: time, arrivalCity: str, arrivalTime: time): 5 | if not isinstance(identifier, str): 6 | raise TypeError("Identifier should be a string") 7 | if not isinstance(departureTime, time): 8 | raise TypeError("Departure time should be a time instance") 9 | 10 | self.__identifier = identifier 11 | self.__departureCity = departureCity 12 | self.__departureTime = departureTime 13 | self.__arrivalCity = arrivalCity 14 | self.__arrivalTime = arrivalTime 15 | 16 | @property 17 | def identifier(self): 18 | return self.__identifier 19 | 20 | @property 21 | def departureTime(self): 22 | return self.__departureTime 23 | 24 | @property 25 | def departureCity(self): 26 | return self.__departureCity 27 | 28 | @property 29 | def arrivalCity(self): 30 | return self.__arrivalCity 31 | 32 | @property 33 | def arrivalTime(self): 34 | return self.__arrivalTime 35 | 36 | def __str__(self): 37 | return "Flight " + self.identifier + " departs from " + self.departureCity + " at " + str( 38 | self.departureTime) + ", arrives at " + self.arrivalCity + " at " + str(self.arrivalTime) 39 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_8/game.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | from seminar.group913.seminar_8.board import Board 4 | 5 | """ 6 | Strategy design pattern 7 | https://refactoring.guru/design-patterns/strategy 8 | """ 9 | 10 | 11 | class RandomComputerMove: 12 | """ 13 | This class has one move() method which receives the state of the board as a parameter and makes its move 14 | on the board, returning the move coordinates 15 | """ 16 | 17 | def __init__(self, board: Board): 18 | self.__board = board 19 | 20 | def move(self) -> tuple: 21 | row, col = choice(self.__board.get_free_squares()) # tuple unpacking 22 | self.__board.move('O', row, col) 23 | return row, col 24 | 25 | 26 | class SmartComputerMove: 27 | def __init__(self, board: Board): 28 | self.__board = board 29 | 30 | def move(self) -> tuple: 31 | # TODO Implement me! 32 | pass 33 | 34 | 35 | class Game: 36 | def __init__(self, computer_algorithm): 37 | self.__board = Board() 38 | self.__algorithm = computer_algorithm 39 | 40 | def get_board(self): 41 | # NOTE This exposes the board object used internally 42 | return self.__board 43 | 44 | def move_human(self, row: int, col: int) -> None: 45 | self.__board.move('X', row, col) 46 | 47 | def move_computer(self) -> tuple: 48 | self.__algorithm.move() 49 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar12/requirements.txt: -------------------------------------------------------------------------------- 1 | Implement a (simplified) game of Battleship. 2 | 3 | Human and computer players have one board each with 1 ship of length 3, placed horizontally. 4 | Human player can choose where to place their ship. 5 | Computer player places ship randomly. 6 | 7 | Both computer and human player take turns in firing upon the other's board: 8 | --human chooses row and column to hit 9 | --computer fires randomly 10 | 11 | If either of the player's ships is sunk, then the game is over. 12 | 13 | The boards will be shown in a manner similar to this (computer 14 | board hides ship): 15 | 16 | Player 17 | +---+---+---+---+---+---+ 18 | | / | A | B | C | D | E | 19 | +===+===+===+===+===+===+ 20 | | 1 | | | X | X | X | 21 | +---+---+---+---+---+---+ 22 | | 2 | | | | | | 23 | +---+---+---+---+---+---+ 24 | | 3 | | | | | | 25 | +---+---+---+---+---+---+ 26 | | 4 | | | | | | 27 | +---+---+---+---+---+---+ 28 | | 5 | | | | | | 29 | +---+---+---+---+---+---+ 30 | 31 | Computer 32 | +---+---+---+---+---+---+ 33 | | / | A | B | C | D | E | 34 | +===+===+===+===+===+===+ 35 | | 1 | | | | | | 36 | +---+---+---+---+---+---+ 37 | | 2 | | | | | | 38 | +---+---+---+---+---+---+ 39 | | 3 | | | | | | 40 | +---+---+---+---+---+---+ 41 | | 4 | | | | | | 42 | +---+---+---+---+---+---+ 43 | | 5 | | | | | | 44 | +---+---+---+---+---+---+ -------------------------------------------------------------------------------- /src/seminar/group916/Seminar12/requirements.txt: -------------------------------------------------------------------------------- 1 | Implement a (simplified) game of Battleship. 2 | 3 | Human and computer players have one board each with 1 ship of length 3, placed horizontally. 4 | Human player can choose where to place their ship. 5 | Computer player places ship randomly. 6 | 7 | Both computer and human player take turns in firing upon the other's board: 8 | --human chooses row and column to hit 9 | --computer fires randomly 10 | 11 | If either of the player's ships is sunk, then the game is over. 12 | 13 | The boards will be shown in a manner similar to this (computer 14 | board hides ship): 15 | 16 | Player 17 | +---+---+---+---+---+---+ 18 | | / | A | B | C | D | E | 19 | +===+===+===+===+===+===+ 20 | | 1 | | | H | X | X | 21 | +---+---+---+---+---+---+ 22 | | 2 | | | | | * | 23 | +---+---+---+---+---+---+ 24 | | 3 | | | | | | 25 | +---+---+---+---+---+---+ 26 | | 4 | | | | | | 27 | +---+---+---+---+---+---+ 28 | | 5 | | | | | | 29 | +---+---+---+---+---+---+ 30 | 31 | Computer 32 | +---+---+---+---+---+---+ 33 | | / | A | B | C | D | E | 34 | +===+===+===+===+===+===+ 35 | | 1 | | | | | | 36 | +---+---+---+---+---+---+ 37 | | 2 | | | | | | 38 | +---+---+---+---+---+---+ 39 | | 3 | | | | | | 40 | +---+---+---+---+---+---+ 41 | | 4 | | | | | | 42 | +---+---+---+---+---+---+ 43 | | 5 | | | | | | 44 | +---+---+---+---+---+---+ -------------------------------------------------------------------------------- /src/seminar/group917/Seminar12/requirements.txt: -------------------------------------------------------------------------------- 1 | Implement a (simplified) game of Battleship. 2 | 3 | Human and computer players have one board each with 1 ship of length 3, placed horizontally. 4 | Human player can choose where to place their ship. 5 | Computer player places ship randomly. 6 | 7 | Both computer and human player take turns in firing upon the other's board: 8 | --human chooses row and column to hit 9 | --computer fires randomly 10 | 11 | If either of the player's ships is sunk, then the game is over. 12 | 13 | The boards will be shown in a manner similar to this (computer 14 | board hides ship): 15 | 16 | Player 17 | +---+---+---+---+---+---+ 18 | | / | A | B | C | D | E | 19 | +===+===+===+===+===+===+ 20 | | 1 | | | H | X | X | 21 | +---+---+---+---+---+---+ 22 | | 2 | | | | * | | 23 | +---+---+---+---+---+---+ 24 | | 3 | | | | | | 25 | +---+---+---+---+---+---+ 26 | | 4 | | | | | | 27 | +---+---+---+---+---+---+ 28 | | 5 | | | | | | 29 | +---+---+---+---+---+---+ 30 | 31 | Computer 32 | +---+---+---+---+---+---+ 33 | | / | A | B | C | D | E | 34 | +===+===+===+===+===+===+ 35 | | 1 | | | | | | 36 | +---+---+---+---+---+---+ 37 | | 2 | | | | | | 38 | +---+---+---+---+---+---+ 39 | | 3 | | | | | | 40 | +---+---+---+---+---+---+ 41 | | 4 | | | | | | 42 | +---+---+---+---+---+---+ 43 | | 5 | | | | | | 44 | +---+---+---+---+---+---+ -------------------------------------------------------------------------------- /src/seminar/group917/Seminar9/ui/ui.py: -------------------------------------------------------------------------------- 1 | from Seminar917.Seminar9.repository.carRepositoryBinary import CarRepositoryBinary 2 | from Seminar917.Seminar9.domain.car import Car 3 | 4 | class UI: 5 | def __init__(self): 6 | self.__repo = CarRepositoryBinary("cars.pickle") 7 | 8 | def printMenu(self): 9 | print("0. Exit") 10 | print("1. Add car") 11 | print("2. Remove car") 12 | print("3. See all cars") 13 | 14 | def start(self): 15 | while True: 16 | self.printMenu() 17 | 18 | try: 19 | choice = input("Your choice: ") 20 | if choice == "0": 21 | break 22 | elif choice == "1": 23 | licensePlate = input("License Plate: ") 24 | brand = input("Brand: ") 25 | model = input("Model: ") 26 | color = input("Color: ") 27 | self.__repo.addCar(Car(licensePlate, brand, model, color)) 28 | elif choice == "2": 29 | licensePlate = input("License Plate: ") 30 | self.__repo.removeCar(licensePlate) 31 | elif choice == "3": 32 | print(self.__repo.getAllCars()) 33 | else: continue 34 | except Exception as e: 35 | print(e) 36 | 37 | if __name__=="__main__": 38 | ui = UI() 39 | ui.start() -------------------------------------------------------------------------------- /src/seminar/group913/seminar_8/ui.py: -------------------------------------------------------------------------------- 1 | from seminar.group913.seminar_8.game import Game, RandomComputerMove, SmartComputerMove 2 | 3 | 4 | class UI: 5 | def __init__(self): 6 | # not a smart opponent 7 | self.__game = Game(RandomComputerMove()) 8 | # yes! 9 | # self.__game = Game(SmartComputerMove()) 10 | 11 | def play(self): 12 | b = self.__game.get_board() 13 | is_players_turn = True 14 | print(b) 15 | 16 | while not (b.is_won() or b.is_full()): 17 | if is_players_turn: 18 | try: 19 | row = int(input("X=")) 20 | col = int(input("Y=")) 21 | self.__game.move_human(row, col) 22 | except ValueError as ve: 23 | print(ve) 24 | is_players_turn = not is_players_turn 25 | else: 26 | row, col = self.__game.move_computer() 27 | print(f"Computer played at ({row},{col})") 28 | print(b) 29 | is_players_turn = not is_players_turn 30 | 31 | if b.is_won(): 32 | if is_players_turn: 33 | print("Game over. Computer wins") 34 | else: 35 | print("Congrats!") 36 | elif b.is_full(): 37 | print("It's a draw!") 38 | print(b) 39 | 40 | 41 | if __name__ == "__main__": 42 | ui = UI() 43 | ui.play() 44 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_14/repository.py: -------------------------------------------------------------------------------- 1 | from domain import Flight 2 | 3 | class FlightRepo: 4 | def __init__(self, filename="flights.txt"): 5 | self.__flights = {} 6 | self.__filename = filename 7 | self.__load() 8 | 9 | def __load(self): 10 | try: 11 | with open(self.__filename, "r") as f: 12 | for line in f: 13 | flight = line.strip().split(",") 14 | self.__flights[flight[0]] = Flight(flight[0], flight[1], flight[2], flight[3], flight[4]) 15 | except FileNotFoundError: 16 | raise ValueError("File not found") 17 | 18 | def __save(self): 19 | with open(self.__filename, "w") as f: 20 | for flight in self.__flights.values(): 21 | f.write(str(flight.id) + "," + str(flight.departure) + "," + str(flight.departure_time) + "," + str(flight.arrival) + "," + str(flight.arrival_time) + "\n") 22 | 23 | def get_all(self): 24 | return self.__flights.values() 25 | 26 | def add(self, obj): 27 | if obj.id in self.__flights: 28 | raise ValueError("Flight already exists") 29 | self.__flights[obj.id] = obj 30 | self.__save() 31 | 32 | def remove(self, id): 33 | if id not in self.__flights: 34 | raise ValueError("Flight does not exist") 35 | del self.__flights[id] 36 | self.__save() 37 | 38 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_8/calc.py: -------------------------------------------------------------------------------- 1 | from lecture.livecoding.lecture_8.rational import Rational 2 | 3 | 4 | class CalculatorError(Exception): 5 | pass 6 | 7 | 8 | class Calculator: 9 | def __init__(self): 10 | """ 11 | Create a calculator with a default value 12 | 13 | :return: The calculator initialized with the default value of 0 14 | """ 15 | self.__value = Rational(0) 16 | self.__history = [] 17 | # return {"value": create_rational(0), "history": []} 18 | 19 | @property 20 | def value(self): 21 | return self.__value 22 | 23 | @value.setter 24 | def value(self, new_value): 25 | # append the old calculator value to the list 26 | self.__history.append(self.value) 27 | self.__value = new_value 28 | 29 | def add(self, q) -> None: 30 | """ 31 | Add a rational number to the calculator 32 | 33 | :param calculator: The calculator's current state 34 | :param q: The number to add 35 | """ 36 | # current_value = get_calc_value(calculator) 37 | # new_value = add_rational(current_value, q) 38 | self.value += q 39 | 40 | def undo(self) -> None: 41 | if len(self.__history) == 0: 42 | raise CalculatorError("Undo not available") 43 | last_value = self.__history.pop() 44 | # set_calc_value(calculator, last_value) 45 | self.__value = last_value 46 | # _set_calc_value_internal(calculator, last_value) 47 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar9/domain/car.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def getRndLetter(): 4 | letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 5 | return letters[random.randint(0, len(letters) - 1)] 6 | 7 | 8 | def generateLicensePlate(): 9 | return getRndLetter() + getRndLetter() + " " + str(random.randint(10, 99)) + " " + getRndLetter() + getRndLetter() + getRndLetter() 10 | 11 | 12 | class Car: 13 | def __init__(self, licensePlate: str, brand: str, model: str, color: str): 14 | self.__licensePlate = licensePlate 15 | self.__brand = brand 16 | self.__model = model 17 | self.__color = color 18 | 19 | @property 20 | def licensePlate(self): 21 | return self.__licensePlate 22 | 23 | def getCarBrand(self): 24 | return self.__brand 25 | 26 | def getCarModel(self): 27 | return self.__model 28 | 29 | def getCarColor(self): 30 | return self.__color 31 | 32 | def __eq__(self, other): 33 | return self.licensePlate == other.licensePlate 34 | 35 | def __str__(self): 36 | return self.__licensePlate + " " + self.__brand + " " + self.__model + " " + self.__color 37 | 38 | def generateNCars(n: int): 39 | cars = [] 40 | for i in range(n): 41 | car = Car(generateLicensePlate(), "Volkswagen", "Golf", "Gray") 42 | cars.append(car) 43 | 44 | return cars 45 | 46 | if __name__=="__main__": 47 | car = Car("CJ 12 ABC", "Audi", "Model1", "Black") 48 | print(car.licensePlate) 49 | #car.licensePlate = "LALALa" 50 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_7/rational_as_dict.py: -------------------------------------------------------------------------------- 1 | from math import gcd 2 | 3 | from pdoc import pdoc 4 | 5 | 6 | def create_rational(num: int, denom: int = 1): 7 | """ 8 | Create a rational number 9 | 10 | This is a *bit of* written **text**. 11 | 12 | an example of calling the function 13 | >>> create_rational(1, 2) 14 | 15 | :param num: numerator 16 | :param denom: non-zero denominator 17 | :return: the created number 18 | 19 | :raises: Raises ValueError in case the denom is 0 20 | """ 21 | if denom == 0: 22 | raise ValueError("Denominator must be non-0") 23 | 24 | _gcd = gcd(num, denom) 25 | return {"num": num // _gcd, "denom": denom // _gcd} 26 | 27 | 28 | def get_numerator(q) -> int: 29 | return q["num"] 30 | 31 | 32 | def get_denominator(q) -> int: 33 | return q["denom"] 34 | 35 | 36 | def to_str(q) -> str: 37 | # TODO fix 1/-2, 5/-1 etc. 38 | if get_denominator(q) == 1: 39 | return str(get_numerator(q)) 40 | return str(get_numerator(q)) + "/" + str(get_denominator(q)) 41 | 42 | 43 | def add_rational(q1, q2): 44 | gn = get_numerator # () -- function call operator 45 | gd = get_denominator 46 | num = gn(q1) * gd(q2) + gn(q2) * gd(q1) 47 | denom = gd(q1) * gd(q2) 48 | return create_rational(num, denom) 49 | 50 | 51 | if __name__ == "__main__": 52 | """ 53 | Generate HTML documentation using the pdoc package 54 | """ 55 | f = open("doc.html", "wt") 56 | f.write(pdoc("rational_as_dict.py", "")) 57 | f.close() -------------------------------------------------------------------------------- /src/lecture/examples/ex42_tdd_1.py: -------------------------------------------------------------------------------- 1 | """ 2 | 1. Write a test function 3 | """ 4 | 5 | 6 | def test_gcd(): 7 | assert gcd(0, 2) == 2 8 | assert gcd(2, 0) == 2 9 | assert gcd(1, 2) == 1 10 | assert gcd(2, 1) == 1 11 | assert gcd(6, 2) == 2 12 | assert gcd(6, 3) == 3 13 | assert gcd(21, 2) == 1 14 | assert gcd(2, 21) == 1 15 | assert gcd(210, 15) == 15 16 | assert gcd(15, 210) == 15 17 | 18 | 19 | ''' 20 | Write a first version of the function 21 | ''' 22 | 23 | 24 | def gcd(a, b): 25 | """ 26 | Calculates the GCD of a and b 27 | a,b - input integers, a,b >= 0 28 | Returns the GCD of positive integers a and b 29 | """ 30 | pass 31 | 32 | 33 | ''' 34 | 2. Run the test function. 35 | 36 | NB! 37 | If it passes, you've done something wrong :-) 38 | ''' 39 | test_gcd() 40 | 41 | ''' 42 | 3. Write the gcd function according to its specification 43 | ''' 44 | # def gcd(a, b): 45 | # ''' 46 | # Calculates the GCD of a and b 47 | # a,b - input integers, a,b >= 0 48 | # Returns the GCD of positive integers a and b 49 | # ''' 50 | # if a == 0: 51 | # return b 52 | # if b == 0: 53 | # return a 54 | # while a != b: 55 | # if a > b: 56 | # a -= b 57 | # else: 58 | # b -= a 59 | # return a 60 | 61 | ''' 62 | 4. Run the test(s) again 63 | 64 | NB! 65 | If they fail, you've done something wrong :-< 66 | ''' 67 | # test_gcd() 68 | 69 | 70 | ''' 71 | 5. Refactor / optimize the function 72 | ''' 73 | -------------------------------------------------------------------------------- /src/lecture/examples/ex11_search_comparison.py: -------------------------------------------------------------------------------- 1 | import timeit 2 | from texttable import Texttable 3 | 4 | from ex08_sequential_search import search_iter 5 | from ex09_binary_search import binary_search_iter, binary_search_rec 6 | from ex10_exponential_search import exponential_search 7 | 8 | 9 | def generate_list(length: int): 10 | """ 11 | Generate a list of given length with elements [0, ... , n-1] 12 | :return: The newly generated list 13 | """ 14 | return list(range(length)) 15 | 16 | 17 | ''' 18 | NB! 19 | To run the function below, you must have installed the texttable component from: 20 | https://github.com/foutaise/texttable 21 | ''' 22 | 23 | 24 | def build_result_table(algorithms: list, list_lengths: list): 25 | table = Texttable() 26 | table.add_row(['algorithm'] + list_lengths) 27 | 28 | for algorithm in algorithms: 29 | table_row = [algorithm.__name__] 30 | for list_length in list_lengths: 31 | data = generate_list(list_length) 32 | t1 = timeit.default_timer() 33 | # (list_length // 2) is at the middle of the list 34 | algorithm(data, list_length // 2) 35 | t2 = timeit.default_timer() 36 | table_row.append(t2 - t1) 37 | table.add_row(table_row) 38 | return table 39 | 40 | 41 | if __name__ == "__main__": 42 | list_lengths = [1_000_000, 2_000_000, 4_000_000, 8_000_000, 16_000_000] 43 | algorithms = [search_iter, binary_search_iter, binary_search_rec, exponential_search] 44 | print(build_result_table(algorithms, list_lengths).draw()) 45 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/domain/car.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def getRndLetter(): 4 | letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 5 | return letters[random.randint(0, len(letters) - 1)] 6 | 7 | 8 | def generateLicensePlate(): 9 | return getRndLetter() + getRndLetter() + " " + str(random.randint(10, 99)) + " " + getRndLetter() + getRndLetter() + getRndLetter() 10 | 11 | 12 | class Car: 13 | def __init__(self, lPlate: str, brand: str, model: str, color: str): 14 | self.__licensePlate = lPlate 15 | self.__brand = brand 16 | self.__model = model 17 | self.__color = color 18 | 19 | def getLicensePlate(self): 20 | return self.__licensePlate 21 | 22 | @property 23 | def brand(self): 24 | return self.__brand 25 | 26 | @property 27 | def model(self): 28 | return self.__model 29 | 30 | @property 31 | def color(self): 32 | return self.__color 33 | 34 | def __str__(self): 35 | return self.__licensePlate + " " + self.__brand + " " + self.__model + " " + self.__color 36 | 37 | def generateNRandomCars(n: int): 38 | cars = [] 39 | for i in range(n): 40 | car = Car(generateLicensePlate(), "Volkswagen", "Golf", "White") 41 | cars.append(car) 42 | 43 | return cars 44 | 45 | if __name__=="__main__": 46 | car = Car("CJ 23 ABC", "Audi", "Model1", "Black") 47 | car1 = Car(generateLicensePlate(), "Volkswagen", "Golf", "Red") 48 | print(car1) 49 | print(car.getLicensePlate()) 50 | print(car.brand) 51 | #car.brand = "Volkswagen" 52 | print(car) 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/ui/ui.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar9.repository.carsRepositoryBinary import CarRepositoryBinary 2 | from Seminar915.Seminar9.domain.car import Car 3 | from Seminar915.Seminar9.repository.carsRepositoryInMemory import RepositoryError 4 | 5 | 6 | class UI: 7 | def __init__(self): 8 | self.__repo = CarRepositoryBinary("cars.pickle") 9 | 10 | def printMenu(self): 11 | print("0. Exit") 12 | print("1. Add car") 13 | print("2. Remove car") 14 | print("3. See all cars") 15 | 16 | 17 | def start(self): 18 | while True: 19 | self.printMenu() 20 | 21 | choice = input("Your choice: ") 22 | if choice == "0": 23 | break 24 | elif choice == "1": 25 | try: 26 | licensePlate = input("License Plate: ") 27 | brand = input("Brand: ") 28 | model = input("Model: ") 29 | color = input("Color: ") 30 | 31 | self.__repo.addCar(Car(licensePlate, brand, model, color)) 32 | except RepositoryError as re: 33 | print(re) 34 | elif choice == "2": 35 | try: 36 | licensePlate = input("License Plate: ") 37 | self.__repo.removeCar(licensePlate) 38 | except RepositoryError as re: 39 | print(re) 40 | elif choice == "3": 41 | print(self.__repo.getAllCars()) 42 | else: 43 | continue 44 | 45 | if __name__=="__main__": 46 | ui = UI() 47 | ui.start() -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/ui/ui.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar9.repository.carRepositoryBinary import CarRepositoryBinary 2 | from Seminar916.Seminar9.domain.car import Car 3 | from Seminar916.Seminar9.repository.carRepositoryInMemory import RepositoryError 4 | 5 | 6 | class UI: 7 | def __init__(self): 8 | self.__repo = CarRepositoryBinary("cars.pickle") 9 | 10 | def printMenu(self): 11 | print("0. Exit") 12 | print("1. Add car") 13 | print("2. Remove car") 14 | print("3. See all cars") 15 | 16 | def start(self): 17 | while True: 18 | self.printMenu() 19 | 20 | choice = input("Your choice: ") 21 | 22 | if choice == "0": 23 | break 24 | elif choice == "1": 25 | try: 26 | licensePlate = input("License Plate: ") 27 | brand = input("Brand: ") 28 | model = input("Model: ") 29 | color = input("Color: ") 30 | 31 | self.__repo.addCar(Car(licensePlate, brand, model, color)) 32 | except RepositoryError as e: 33 | print(e) 34 | 35 | elif choice == "2": 36 | try: 37 | licensePlate = input("License Plate: ") 38 | self.__repo.removeCar(licensePlate) 39 | except RepositoryError as e: 40 | print(e) 41 | elif choice == "3": 42 | print(self.__repo.getAllCars()) 43 | else: 44 | continue 45 | 46 | if __name__=="__main__": 47 | ui = UI() 48 | ui.start() -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/domain/car.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | 4 | def getRandomLetter(): 5 | letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 6 | return letters[random.randint(0, len(letters) - 1)] 7 | 8 | 9 | def generateLicensePlate(): 10 | return getRandomLetter() + getRandomLetter() + " " + str(random.randint(10, 99)) + " " + getRandomLetter() + getRandomLetter() + getRandomLetter() 11 | 12 | 13 | class Car: 14 | def __init__(self, licensePlate: str, brand: str, model: str, color: str): 15 | self.__licensePlate = licensePlate 16 | self.__brand = brand 17 | self.__model = model 18 | self.__color = color 19 | 20 | def getCarBrand(self): 21 | return self.__brand 22 | 23 | @property 24 | def licensePlate(self): 25 | return self.__licensePlate 26 | 27 | def getCarModel(self): 28 | return self.__model 29 | 30 | def getCarColor(self): 31 | return self.__color 32 | 33 | def __str__(self): 34 | return self.licensePlate + " " + self.__brand + " " + self.__model + " " + self.__color 35 | 36 | def __eq__(self, other): 37 | # TODO implement this if you want to directly compare objects of type Car 38 | pass 39 | 40 | 41 | def generateNRandomCars(n: int): 42 | cars = [] 43 | 44 | for i in range(n): 45 | car = Car(generateLicensePlate(), "Volkswagen", "Golf", "Pink") 46 | cars.append(car) 47 | 48 | return cars 49 | 50 | 51 | if __name__ == "__main__": 52 | car = Car("CJ 23 ABX", "Audi", "Model1", "Green") 53 | 54 | print(car.getCarBrand()) 55 | print(car.licensePlate) 56 | #car.licensePlate = "LALA" 57 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date, timedelta 2 | 3 | from seminar10.domain.client import Client 4 | from seminar10.domain.car import Car 5 | 6 | 7 | class Rental: 8 | def __init__(self, rental_id: int, start: date, end: date, client, car): 9 | self.__id = rental_id 10 | self.__client = client 11 | self.__car = car 12 | self.__start = start 13 | self.__end = end 14 | 15 | @property 16 | def id(self): 17 | return self.__id 18 | 19 | @property 20 | def client(self): 21 | return self.__client 22 | 23 | @property 24 | def car(self): 25 | return self.__car 26 | 27 | @property 28 | def start(self): 29 | return self.__start 30 | 31 | @property 32 | def end(self): 33 | return self.__end 34 | 35 | # len(rental) 36 | def __len__(self): 37 | if self.__end is not None: 38 | return (self.__end - self.__start).days + 1 39 | today = date.today() 40 | return (today - self.__start).days + 1 41 | 42 | 43 | def __str__(self): 44 | # return 45 | from_date = self.__start.strftime("%Y-%m-%d") 46 | to_date = self.__end.strftime("%Y-%m-%d") 47 | return f"{self.id} - [car {self.car}] - [client {self.client}] - from {from_date} to {to_date}" 48 | 49 | 50 | if __name__ == "__main__": 51 | d1 = date(2020, 12, 15) 52 | d2 = date(2022, 12, 15) 53 | 54 | car = Car(100, "AB 01 ERT", "VW", "Tiguan", "Black") 55 | client = Client(200, "Popescu Marcel") 56 | rent = Rental(300, date(2024, 11, 30), date(2024, 12, 5), client, car) 57 | 58 | print(rent) -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | from seminar11.domain.validator_exception import ValidatorException 4 | 5 | 6 | class Rental: 7 | def __init__(self, _id, start, end, client, car): 8 | self._id = _id 9 | self._client = client 10 | self._car = car 11 | self._start = start 12 | self._end = end 13 | 14 | @property 15 | def id(self): 16 | return self._id 17 | 18 | @property 19 | def client(self): 20 | return self._client 21 | 22 | @property 23 | def car(self): 24 | return self._car 25 | 26 | @property 27 | def start(self): 28 | return self._start 29 | 30 | @property 31 | def end(self): 32 | return self._end 33 | 34 | def __len__(self): 35 | return (self._end - self._start).days + 1 36 | 37 | def __repr__(self): 38 | return str(self) 39 | 40 | def __str__(self): 41 | return "Rental: " + str(self.id) + "\nCar: " + str(self.car) + "\nClient: " + str( 42 | self.client) + "\nPeriod: " + self.start.strftime("%Y-%m-%d") + " to " + self.end.strftime("%Y-%m-%d") 43 | 44 | 45 | class RentalValidator: 46 | 47 | def validate(self, rental): 48 | if isinstance(rental, Rental) is False: 49 | raise TypeError("Not a Rental") 50 | _errorList = [] 51 | now = date(2000, 1, 1) 52 | if rental.start < now: 53 | _errorList.append("Rental starts in past;") 54 | if len(rental) < 1: 55 | _errorList.append("Rental must be at least 1 day;") 56 | if len(_errorList) > 0: 57 | raise ValidatorException(_errorList) -------------------------------------------------------------------------------- /src/lecture/examples/ex20_longest_increasing_subsequence.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Jan 11, 2017 3 | 4 | @author: Arthur 5 | """ 6 | 7 | 8 | def longest_increasing_subsequence(A): 9 | """ 10 | Maximum length of subsequence recorded so far, as well as its end index 11 | """ 12 | max_length = 1 13 | best_end = 0 14 | 15 | indices_array = [1] 16 | previous_indices = [-1] 17 | 18 | for i in range(1, len(A)): 19 | ''' 20 | The maximum length of the increasing subsequence ending at index i 21 | ''' 22 | indices_array.append(1) 23 | previous_indices.append(-1) 24 | 25 | ''' 26 | The maximum length is increased by 1 if 'j' exists, so that: 27 | A[j] < A[i] and the length of the subsequence would increase 28 | ''' 29 | for j in range(i - 1, -1, -1): 30 | if (indices_array[j] + 1 > indices_array[i]) and (A[j] < A[i]): 31 | indices_array[i] = indices_array[j] + 1 32 | previous_indices[i] = j 33 | 34 | ''' 35 | Record the end index in the same go 36 | ''' 37 | if indices_array[i] > max_length: 38 | best_end = i 39 | max_length = indices_array[i] 40 | 41 | ''' 42 | Build the solution using the previous_indices list 43 | ''' 44 | solution = [A[best_end]] 45 | while previous_indices[best_end] != -1: 46 | solution.append(A[previous_indices[best_end]]) 47 | best_end = previous_indices[best_end] 48 | 49 | solution.reverse() 50 | return solution 51 | 52 | 53 | A = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15] 54 | print(longest_increasing_subsequence(A)) 55 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/domain/car.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def getRndLetter(): 4 | letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 5 | return letters[random.randint(0, len(letters) - 1)] 6 | 7 | 8 | def generateLicensePlate(): 9 | return getRndLetter() + getRndLetter() + " " + str(random.randint(10, 99)) + " " + getRndLetter() + getRndLetter() + getRndLetter() 10 | 11 | 12 | class Car: 13 | def __init__(self, carId, licensePlate: str, brand: str, model: str, color: str): 14 | self.__id = carId 15 | self.__licensePlate = licensePlate 16 | self.__brand = brand 17 | self.__model = model 18 | self.__color = color 19 | 20 | @property 21 | def id(self): 22 | return self.__id 23 | 24 | @property 25 | def licensePlate(self): 26 | return self.__licensePlate 27 | 28 | def getCarBrand(self): 29 | return self.__brand 30 | 31 | def getCarModel(self): 32 | return self.__model 33 | 34 | def getCarColor(self): 35 | return self.__color 36 | 37 | def __eq__(self, other): 38 | return self.licensePlate == other.licensePlate 39 | 40 | def __str__(self): 41 | return str(self.__id) + " " + self.__licensePlate + " " + self.__brand + " " + self.__model + " " + self.__color 42 | 43 | def generateNCars(n: int): 44 | cars = [] 45 | for i in range(n): 46 | car = Car(generateLicensePlate(), "Volkswagen", "Golf", "Gray") 47 | cars.append(car) 48 | 49 | return cars 50 | 51 | if __name__=="__main__": 52 | car = Car(1, "CJ 12 ABC", "Audi", "Model1", "Black") 53 | print(car) 54 | print(car.licensePlate) 55 | #car.licensePlate = "LALALa" 56 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar10/domain/car.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def getRndLetter(): 4 | letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 5 | return letters[random.randint(0, len(letters) - 1)] 6 | 7 | 8 | def generateLicensePlate(): 9 | return getRndLetter() + getRndLetter() + " " + str(random.randint(10, 99)) + " " + getRndLetter() + getRndLetter() + getRndLetter() 10 | 11 | 12 | class Car: 13 | def __init__(self, carId, licensePlate: str, brand: str, model: str, color: str): 14 | self.__id = carId 15 | self.__licensePlate = licensePlate 16 | self.__brand = brand 17 | self.__model = model 18 | self.__color = color 19 | 20 | @property 21 | def id(self): 22 | return self.__id 23 | 24 | @property 25 | def licensePlate(self): 26 | return self.__licensePlate 27 | 28 | def getCarBrand(self): 29 | return self.__brand 30 | 31 | def getCarModel(self): 32 | return self.__model 33 | 34 | def getCarColor(self): 35 | return self.__color 36 | 37 | def __eq__(self, other): 38 | return self.licensePlate == other.licensePlate 39 | 40 | def __str__(self): 41 | return str(self.__id) + " " + self.__licensePlate + " " + self.__brand + " " + self.__model + " " + self.__color 42 | 43 | def generateNCars(n: int): 44 | cars = [] 45 | for i in range(n): 46 | car = Car(generateLicensePlate(), "Volkswagen", "Golf", "Gray") 47 | cars.append(car) 48 | 49 | return cars 50 | 51 | if __name__=="__main__": 52 | car = Car(1, "CJ 12 ABC", "Audi", "Model1", "Black") 53 | print(car) 54 | print(car.licensePlate) 55 | #car.licensePlate = "LALALa" 56 | -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/domain/car.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def getRndLetter(): 4 | letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 5 | return letters[random.randint(0, len(letters) - 1)] 6 | 7 | 8 | def generateLicensePlate(): 9 | return getRndLetter() + getRndLetter() + " " + str(random.randint(10, 99)) + " " + getRndLetter() + getRndLetter() + getRndLetter() 10 | 11 | 12 | class Car: 13 | def __init__(self, carId, licensePlate: str, brand: str, model: str, color: str): 14 | self.__id = carId 15 | self.__licensePlate = licensePlate 16 | self.__brand = brand 17 | self.__model = model 18 | self.__color = color 19 | 20 | @property 21 | def id(self): 22 | return self.__id 23 | 24 | @property 25 | def licensePlate(self): 26 | return self.__licensePlate 27 | 28 | def getCarBrand(self): 29 | return self.__brand 30 | 31 | def getCarModel(self): 32 | return self.__model 33 | 34 | def getCarColor(self): 35 | return self.__color 36 | 37 | def __eq__(self, other): 38 | return self.licensePlate == other.licensePlate 39 | 40 | def __str__(self): 41 | return str(self.__id) + " " + self.__licensePlate + " " + self.__brand + " " + self.__model + " " + self.__color 42 | 43 | def generateNCars(n: int): 44 | cars = [] 45 | for i in range(n): 46 | car = Car(generateLicensePlate(), "Volkswagen", "Golf", "Gray") 47 | cars.append(car) 48 | 49 | return cars 50 | 51 | if __name__=="__main__": 52 | car = Car(1, "CJ 12 ABC", "Audi", "Model1", "Black") 53 | print(car) 54 | print(car.licensePlate) 55 | #car.licensePlate = "LALALa" 56 | -------------------------------------------------------------------------------- /src/lecture/examples/ex36_rational_calc/test_calculator.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | 3 | from lecture.examples.ex36_rational_calc.domain import Rational 4 | 5 | 6 | class TestCalculator(TestCase): 7 | def test_rational_add(self): 8 | r1 = Rational(1, 2) 9 | r2 = Rational(1, 3) 10 | r3 = r1.add(r2) 11 | assert r3.num == 5 12 | assert r3.denom == 6 13 | assert r3 == Rational(5, 6) 14 | 15 | def test_equal(self): 16 | """ 17 | test function for testing == for 2 rational numbers 18 | """ 19 | r1 = Rational(1, 3) 20 | assert r1 == r1 21 | r2 = Rational(1, 3) 22 | assert r1 == r2 23 | r1 = Rational(1, 3) 24 | r1 = r1.add(Rational(2, 3)) 25 | r2 = Rational(1, 1) 26 | assert r1 == r2 27 | 28 | def test_compare_operator(self): 29 | """ 30 | Test function for < > 31 | """ 32 | r1 = Rational(1, 3) 33 | r2 = Rational(2, 3) 34 | assert r2 > r1 35 | assert r1 < r2 36 | 37 | def test_add_operator(self): 38 | """ 39 | Test function for the + operator 40 | """ 41 | r1 = Rational(1, 3) 42 | r2 = Rational(1, 3) 43 | r3 = r1 + r2 44 | assert r3 == Rational(2, 3) 45 | 46 | def test_create(self): 47 | """ 48 | Test function for creating rational numbers 49 | """ 50 | r1 = Rational(1, 3) # create the rational number 1/3 51 | assert r1.num == 1 52 | assert r1.denom == 3 53 | r1 = Rational(4, 3) # create the rational number 4/3 54 | assert r1.num == 4 55 | assert r1.denom == 3 56 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | from Seminar915.Seminar11.domain.validator_exception import ValidatorException 4 | 5 | 6 | class Rental: 7 | def __init__(self, _id, start, end, client, car): 8 | self._id = _id 9 | self._client = client 10 | self._car = car 11 | self._start = start 12 | self._end = end 13 | 14 | @property 15 | def id(self): 16 | return self._id 17 | 18 | @property 19 | def client(self): 20 | return self._client 21 | 22 | @property 23 | def car(self): 24 | return self._car 25 | 26 | @property 27 | def start(self): 28 | return self._start 29 | 30 | @property 31 | def end(self): 32 | return self._end 33 | 34 | def __len__(self): 35 | return (self._end - self._start).days + 1 36 | 37 | def __repr__(self): 38 | return str(self) 39 | 40 | def __str__(self): 41 | return "Rental: " + str(self.id) + "\nCar: " + str(self.car) + "\nClient: " + str( 42 | self.client) + "\nPeriod: " + self.start.strftime("%Y-%m-%d") + " to " + self.end.strftime("%Y-%m-%d") 43 | 44 | 45 | class RentalValidator: 46 | 47 | def validate(self, rental): 48 | if isinstance(rental, Rental) is False: 49 | raise TypeError("Not a Rental") 50 | _errorList = [] 51 | now = date(2000, 1, 1) 52 | if rental.start < now: 53 | _errorList.append("Rental starts in past;") 54 | if len(rental) < 1: 55 | _errorList.append("Rental must be at least 1 day;") 56 | if len(_errorList) > 0: 57 | raise ValidatorException(_errorList) -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | from Seminar917.Seminar11.domain.validator_exception import ValidatorException 4 | 5 | 6 | class Rental: 7 | def __init__(self, _id, start, end, client, car): 8 | self._id = _id 9 | self._client = client 10 | self._car = car 11 | self._start = start 12 | self._end = end 13 | 14 | @property 15 | def id(self): 16 | return self._id 17 | 18 | @property 19 | def client(self): 20 | return self._client 21 | 22 | @property 23 | def car(self): 24 | return self._car 25 | 26 | @property 27 | def start(self): 28 | return self._start 29 | 30 | @property 31 | def end(self): 32 | return self._end 33 | 34 | def __len__(self): 35 | return (self._end - self._start).days + 1 36 | 37 | def __repr__(self): 38 | return str(self) 39 | 40 | def __str__(self): 41 | return "Rental: " + str(self.id) + "\nCar: " + str(self.car) + "\nClient: " + str( 42 | self.client) + "\nPeriod: " + self.start.strftime("%Y-%m-%d") + " to " + self.end.strftime("%Y-%m-%d") 43 | 44 | 45 | class RentalValidator: 46 | 47 | def validate(self, rental): 48 | if isinstance(rental, Rental) is False: 49 | raise TypeError("Not a Rental") 50 | _errorList = [] 51 | now = date(2000, 1, 1) 52 | if rental.start < now: 53 | _errorList.append("Rental starts in past;") 54 | if len(rental) < 1: 55 | _errorList.append("Rental must be at least 1 day;") 56 | if len(_errorList) > 0: 57 | raise ValidatorException(_errorList) -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | from seminar.group913.seminar_11.domain.validator_exception import ValidatorException 4 | 5 | 6 | class Rental: 7 | def __init__(self, _id, start, end, client, car): 8 | self._id = _id 9 | self._client = client 10 | self._car = car 11 | self._start = start 12 | self._end = end 13 | 14 | @property 15 | def id(self): 16 | return self._id 17 | 18 | @property 19 | def client(self): 20 | return self._client 21 | 22 | @property 23 | def car(self): 24 | return self._car 25 | 26 | @property 27 | def start(self): 28 | return self._start 29 | 30 | @property 31 | def end(self): 32 | return self._end 33 | 34 | def __len__(self): 35 | return (self._end - self._start).days + 1 36 | 37 | def __repr__(self): 38 | return str(self) 39 | 40 | def __str__(self): 41 | return "Rental: " + str(self.id) + "\nCar: " + str(self.car) + "\nClient: " + str( 42 | self.client) + "\nPeriod: " + self.start.strftime("%Y-%m-%d") + " to " + self.end.strftime("%Y-%m-%d") 43 | 44 | 45 | class RentalValidator: 46 | 47 | def validate(self, rental): 48 | if isinstance(rental, Rental) is False: 49 | raise TypeError("Not a Rental") 50 | _errorList = [] 51 | now = date(2000, 1, 1) 52 | if rental.start < now: 53 | _errorList.append("Rental starts in past;") 54 | if len(rental) < 1: 55 | _errorList.append("Rental must be at least 1 day;") 56 | if len(_errorList) > 0: 57 | raise ValidatorException(_errorList) 58 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | 3 | from seminar.group914.seminar_11.domain.validator_exception import ValidatorException 4 | 5 | 6 | class Rental: 7 | def __init__(self, _id, start, end, client, car): 8 | self._id = _id 9 | self._client = client 10 | self._car = car 11 | self._start = start 12 | self._end = end 13 | 14 | @property 15 | def id(self): 16 | return self._id 17 | 18 | @property 19 | def client(self): 20 | return self._client 21 | 22 | @property 23 | def car(self): 24 | return self._car 25 | 26 | @property 27 | def start(self): 28 | return self._start 29 | 30 | @property 31 | def end(self): 32 | return self._end 33 | 34 | def __len__(self): 35 | return (self._end - self._start).days + 1 36 | 37 | def __repr__(self): 38 | return str(self) 39 | 40 | def __str__(self): 41 | return "Rental: " + str(self.id) + "\nCar: " + str(self.car) + "\nClient: " + str( 42 | self.client) + "\nPeriod: " + self.start.strftime("%Y-%m-%d") + " to " + self.end.strftime("%Y-%m-%d") 43 | 44 | 45 | class RentalValidator: 46 | 47 | def validate(self, rental): 48 | if isinstance(rental, Rental) is False: 49 | raise TypeError("Not a Rental") 50 | _errorList = [] 51 | now = date(2000, 1, 1) 52 | if rental.start < now: 53 | _errorList.append("Rental starts in past;") 54 | if len(rental) < 1: 55 | _errorList.append("Rental must be at least 1 day;") 56 | if len(_errorList) > 0: 57 | raise ValidatorException(_errorList) 58 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client: 2 | def __init__(self, _id, cnp, name): 3 | self._id = _id 4 | self._cnp = cnp 5 | self._name = name 6 | 7 | @property 8 | def id(self): 9 | return self._id 10 | 11 | @property 12 | def cnp(self): 13 | return self._cnp 14 | 15 | @property 16 | def name(self): 17 | return self._name 18 | 19 | def __eq__(self, z): 20 | if isinstance(z, Client) is False: 21 | return False 22 | return self.id == z.id 23 | 24 | def __str__(self): 25 | return "Id=" + str(self.id) + ", Name=" + str(self.name) 26 | 27 | def __repr__(self): 28 | return str(self) 29 | 30 | 31 | class ClientValidator: 32 | def _is_cnp_valid(self, cnp): 33 | # SAALLZZJJNNNC 34 | if len(cnp) != 13: 35 | # This is not x full CNP validation 36 | return False 37 | for x in cnp: 38 | if x < '0' or x > '9': 39 | return False 40 | return True 41 | 42 | def validate(self, client): 43 | """ 44 | Validate if provided Client instance is valid 45 | client - Instance of Client type 46 | Return List of validation errors. An empty list if instance is valid. 47 | """ 48 | if isinstance(client, Client) is False: 49 | raise TypeError("Not x Client") 50 | _errors = [] 51 | if self._is_cnp_valid(client.cnp) is False: 52 | _errors.append("CNP not valid.;") 53 | if len(client.name) == 0: 54 | _errors.append("Name not valid.") 55 | if len(_errors) != 0: 56 | raise ValueError(_errors) -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client: 2 | def __init__(self, _id, cnp, name): 3 | self._id = _id 4 | self._cnp = cnp 5 | self._name = name 6 | 7 | @property 8 | def id(self): 9 | return self._id 10 | 11 | @property 12 | def cnp(self): 13 | return self._cnp 14 | 15 | @property 16 | def name(self): 17 | return self._name 18 | 19 | def __eq__(self, z): 20 | if isinstance(z, Client) is False: 21 | return False 22 | return self.id == z.id 23 | 24 | def __str__(self): 25 | return "Id=" + str(self.id) + ", Name=" + str(self.name) 26 | 27 | def __repr__(self): 28 | return str(self) 29 | 30 | 31 | class ClientValidator: 32 | def _is_cnp_valid(self, cnp): 33 | # SAALLZZJJNNNC 34 | if len(cnp) != 13: 35 | # This is not x full CNP validation 36 | return False 37 | for x in cnp: 38 | if x < '0' or x > '9': 39 | return False 40 | return True 41 | 42 | def validate(self, client): 43 | """ 44 | Validate if provided Client instance is valid 45 | client - Instance of Client type 46 | Return List of validation errors. An empty list if instance is valid. 47 | """ 48 | if isinstance(client, Client) is False: 49 | raise TypeError("Not x Client") 50 | _errors = [] 51 | if self._is_cnp_valid(client.cnp) is False: 52 | _errors.append("CNP not valid.;") 53 | if len(client.name) == 0: 54 | _errors.append("Name not valid.") 55 | if len(_errors) != 0: 56 | raise ValueError(_errors) -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client: 2 | def __init__(self, _id, cnp, name): 3 | self._id = _id 4 | self._cnp = cnp 5 | self._name = name 6 | 7 | @property 8 | def id(self): 9 | return self._id 10 | 11 | @property 12 | def cnp(self): 13 | return self._cnp 14 | 15 | @property 16 | def name(self): 17 | return self._name 18 | 19 | def __eq__(self, z): 20 | if isinstance(z, Client) is False: 21 | return False 22 | return self.id == z.id 23 | 24 | def __str__(self): 25 | return "Id=" + str(self.id) + ", Name=" + str(self.name) 26 | 27 | def __repr__(self): 28 | return str(self) 29 | 30 | 31 | class ClientValidator: 32 | def _is_cnp_valid(self, cnp): 33 | # SAALLZZJJNNNC 34 | if len(cnp) != 13: 35 | # This is not x full CNP validation 36 | return False 37 | for x in cnp: 38 | if x < '0' or x > '9': 39 | return False 40 | return True 41 | 42 | def validate(self, client): 43 | """ 44 | Validate if provided Client instance is valid 45 | client - Instance of Client type 46 | Return List of validation errors. An empty list if instance is valid. 47 | """ 48 | if isinstance(client, Client) is False: 49 | raise TypeError("Not x Client") 50 | _errors = [] 51 | if self._is_cnp_valid(client.cnp) is False: 52 | _errors.append("CNP not valid.;") 53 | if len(client.name) == 0: 54 | _errors.append("Name not valid.") 55 | if len(_errors) != 0: 56 | raise ValueError(_errors) -------------------------------------------------------------------------------- /src/seminar/group913/seminar_11/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client: 2 | def __init__(self, _id, cnp, name): 3 | self._id = _id 4 | self._cnp = cnp 5 | self._name = name 6 | 7 | @property 8 | def id(self): 9 | return self._id 10 | 11 | @property 12 | def cnp(self): 13 | return self._cnp 14 | 15 | @property 16 | def name(self): 17 | return self._name 18 | 19 | def __eq__(self, z): 20 | if isinstance(z, Client) is False: 21 | return False 22 | return self.id == z.id 23 | 24 | def __str__(self): 25 | return "Id=" + str(self.id) + ", Name=" + str(self.name) 26 | 27 | def __repr__(self): 28 | return str(self) 29 | 30 | 31 | class ClientValidator: 32 | def _is_cnp_valid(self, cnp): 33 | # SAALLZZJJNNNC 34 | if len(cnp) != 13: 35 | # This is not x full CNP validation 36 | return False 37 | for x in cnp: 38 | if x < '0' or x > '9': 39 | return False 40 | return True 41 | 42 | def validate(self, client): 43 | """ 44 | Validate if provided Client instance is valid 45 | client - Instance of Client type 46 | Return List of validation errors. An empty list if instance is valid. 47 | """ 48 | if isinstance(client, Client) is False: 49 | raise TypeError("Not x Client") 50 | _errors = [] 51 | if self._is_cnp_valid(client.cnp) is False: 52 | _errors.append("CNP not valid.;") 53 | if len(client.name) == 0: 54 | _errors.append("Name not valid.") 55 | if len(_errors) != 0: 56 | raise ValueError(_errors) 57 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_11/domain/client.py: -------------------------------------------------------------------------------- 1 | class Client: 2 | def __init__(self, _id, cnp, name): 3 | self._id = _id 4 | self._cnp = cnp 5 | self._name = name 6 | 7 | @property 8 | def id(self): 9 | return self._id 10 | 11 | @property 12 | def cnp(self): 13 | return self._cnp 14 | 15 | @property 16 | def name(self): 17 | return self._name 18 | 19 | def __eq__(self, z): 20 | if isinstance(z, Client) is False: 21 | return False 22 | return self.id == z.id 23 | 24 | def __str__(self): 25 | return "Id=" + str(self.id) + ", Name=" + str(self.name) 26 | 27 | def __repr__(self): 28 | return str(self) 29 | 30 | 31 | class ClientValidator: 32 | def _is_cnp_valid(self, cnp): 33 | # SAALLZZJJNNNC 34 | if len(cnp) != 13: 35 | # This is not x full CNP validation 36 | return False 37 | for x in cnp: 38 | if x < '0' or x > '9': 39 | return False 40 | return True 41 | 42 | def validate(self, client): 43 | """ 44 | Validate if provided Client instance is valid 45 | client - Instance of Client type 46 | Return List of validation errors. An empty list if instance is valid. 47 | """ 48 | if isinstance(client, Client) is False: 49 | raise TypeError("Not x Client") 50 | _errors = [] 51 | if self._is_cnp_valid(client.cnp) is False: 52 | _errors.append("CNP not valid.;") 53 | if len(client.name) == 0: 54 | _errors.append("Name not valid.") 55 | if len(_errors) != 0: 56 | raise ValueError(_errors) 57 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar10/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date, timedelta 2 | 3 | from seminar10.domain.client import Client 4 | from seminar10.domain.car import Car 5 | 6 | 7 | class Rental: 8 | def __init__(self, rental_id: int, start: date, end: date, client, car): 9 | self.__id = rental_id 10 | self.__client = client 11 | self.__car = car 12 | self.__start = start 13 | self.__end = end 14 | 15 | @property 16 | def id(self): 17 | return self.__id 18 | 19 | @property 20 | def client(self): 21 | return self.__client 22 | 23 | @property 24 | def car(self): 25 | return self.__car 26 | 27 | @property 28 | def start(self): 29 | return self.__start 30 | 31 | @property 32 | def end(self): 33 | return self.__end 34 | 35 | # len(rental) 36 | def __len__(self): 37 | if self.__end is not None: 38 | return (self.__end - self.__start).days + 1 39 | today = date.today() 40 | return (today - self.__start).days + 1 41 | 42 | def __repr__(self): 43 | return str(self) 44 | 45 | def __str__(self): 46 | # return 47 | from_date = self.__start.strftime("%Y-%m-%d") 48 | to_date = self.__end.strftime("%Y-%m-%d") 49 | return f"{self.id} - [car {self.car}] - [client {self.client}] - from {from_date} to {to_date}" 50 | 51 | 52 | if __name__ == "__main__": 53 | d1 = date(2020, 12, 15) 54 | d2 = date(2022, 12, 15) 55 | 56 | car = Car(100, "AB 01 ERT", "VW", "Tiguan", "Black") 57 | client = Client(200, "Popescu Marcel") 58 | rent = Rental(300, date(2024, 11, 30), date(2024, 12, 5), client, car) 59 | 60 | print(rent) -------------------------------------------------------------------------------- /src/seminar/group917/Seminar10/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date, timedelta 2 | 3 | from seminar10.domain.client import Client 4 | from seminar10.domain.car import Car 5 | 6 | 7 | class Rental: 8 | def __init__(self, rental_id: int, start: date, end: date, client, car): 9 | self.__id = rental_id 10 | self.__client = client 11 | self.__car = car 12 | self.__start = start 13 | self.__end = end 14 | 15 | @property 16 | def id(self): 17 | return self.__id 18 | 19 | @property 20 | def client(self): 21 | return self.__client 22 | 23 | @property 24 | def car(self): 25 | return self.__car 26 | 27 | @property 28 | def start(self): 29 | return self.__start 30 | 31 | @property 32 | def end(self): 33 | return self.__end 34 | 35 | # len(rental) 36 | def __len__(self): 37 | if self.__end is not None: 38 | return (self.__end - self.__start).days + 1 39 | today = date.today() 40 | return (today - self.__start).days + 1 41 | 42 | def __repr__(self): 43 | return str(self) 44 | 45 | def __str__(self): 46 | # return 47 | from_date = self.__start.strftime("%Y-%m-%d") 48 | to_date = self.__end.strftime("%Y-%m-%d") 49 | return f"{self.id} - [car {self.car}] - [client {self.client}] - from {from_date} to {to_date}" 50 | 51 | 52 | if __name__ == "__main__": 53 | d1 = date(2020, 12, 15) 54 | d2 = date(2022, 12, 15) 55 | 56 | car = Car(100, "AB 01 ERT", "VW", "Tiguan", "Black") 57 | client = Client(200, "Popescu Marcel") 58 | rent = Rental(300, date(2024, 11, 30), date(2024, 12, 5), client, car) 59 | 60 | print(rent) -------------------------------------------------------------------------------- /src/lecture/examples/ex31_exceptions.py: -------------------------------------------------------------------------------- 1 | """ 2 | Created on Oct 25, 2016 3 | 4 | @author: Arthur 5 | 6 | Part of this code is taken from: 7 | https://docs.python.org/3/tutorial/errors.html 8 | """ 9 | 10 | """ 11 | Try to enter various (non-integer) values at the prompt given by the code snippet below 12 | """ 13 | 14 | # while True: 15 | # try: 16 | # x = int(input("Please enter a number: ")) 17 | # break 18 | # except ValueError: 19 | # print("Oops! That was no valid number. Try again...") 20 | 21 | 22 | ''' 23 | Try running the program below, and see what happens on different inputs 24 | 25 | NB! 26 | This is not necessarily the correct way to implement error handling, it's just example code. 27 | ''' 28 | end = False 29 | while not end: 30 | try: 31 | val = input("T - TypeError, V - ValueError, K - KeyError, 0 - Exit") 32 | 33 | if val.lower() == 't': 34 | raise TypeError("Well this is a type error!") 35 | elif val.lower() == 'k': 36 | raise KeyError("Your program just raised a key error!") 37 | elif val.lower() == 'v': 38 | raise ValueError("value error!") 39 | else: 40 | end = True 41 | except KeyError as ke: 42 | print("There was a " + str(type(ke)) + " " + str(ke)) 43 | except ValueError as ve: 44 | print("There was a ValueError") 45 | except: 46 | print("There was an exception that was not handled above!") 47 | else: 48 | print("There was no error") 49 | finally: 50 | print( 51 | "The finally block always runs. This is useful for deallocating resources such as closing files, network connections and so on.") 52 | -------------------------------------------------------------------------------- /src/lecture/examples/ex40_black_box_white_box.py: -------------------------------------------------------------------------------- 1 | """ 2 | A function that we want tested 3 | """ 4 | 5 | 6 | def is_prime(nr): 7 | """ 8 | Verify if a number is prime 9 | return True if nr is prime, False otherwise 10 | raise ValueError if nr <= 0 11 | """ 12 | if nr <= 0: 13 | raise ValueError("nr needs to be positive") 14 | if nr == 1: 15 | return False 16 | if nr <= 3: 17 | return True 18 | for i in range(2, nr): 19 | if nr % i == 0: 20 | return False 21 | return True 22 | 23 | 24 | """ 25 | Black-box testing assumes we only have its specification 26 | """ 27 | 28 | 29 | def test_is_prime_black_box(): 30 | for i in range(-100, 1): 31 | try: 32 | is_prime(i) 33 | assert False 34 | except ValueError: 35 | pass 36 | 37 | primes = [2, 3, 5, 7, 11, 13, 17, 19] 38 | for i in range(2, 20): 39 | assert is_prime(i) == (i in primes), "this is the value where it fails: " + str(i) 40 | 41 | 42 | """ 43 | White-box testing - we can see the source code, so we only write the required test cases 44 | """ 45 | 46 | 47 | def test_is_prime_white_box(): 48 | try: 49 | is_prime(-5) 50 | assert False 51 | except ValueError: 52 | pass 53 | 54 | assert is_prime(1) is False, 1 55 | assert is_prime(2) is True, 2 56 | assert is_prime(3) is True, 3 57 | assert is_prime(6) is False, 4 58 | assert is_prime(7) is True, 7 59 | assert is_prime(8) is False, 8 60 | 61 | 62 | """ 63 | Let's run the tests - they should work regardless 64 | """ 65 | if __name__ == "__main__": 66 | test_is_prime_black_box() 67 | test_is_prime_white_box() 68 | -------------------------------------------------------------------------------- /src/lecture/examples/ex09_binary_search.py: -------------------------------------------------------------------------------- 1 | def binary_search_rec(data: list, key): 2 | """ 3 | Binary search, recursive implementation 4 | :param data: List in which search is performed in 5 | :param key: Search key 6 | :return: Position of element, -1 if element was not found 7 | """ 8 | return binary_search_impl(data, key, 0, len(data) - 1) 9 | 10 | 11 | def binary_search_impl(data: list, key, left: int, right: int): 12 | """ 13 | This is an implementation method. _ means that the method should not be called from other modules. 14 | """ 15 | if right < left: 16 | return -1 17 | m = (left + right) // 2 18 | if data[m] > key: 19 | return binary_search_impl(data, key, left, m - 1) 20 | if data[m] < key: 21 | return binary_search_impl(data, key, m + 1, right) 22 | if data[m] == key: 23 | return m 24 | 25 | 26 | def binary_search_iter(data: list, key): 27 | left = 0 28 | right = len(data) - 1 29 | 30 | while left <= right: 31 | middle = (left + right) // 2 32 | if data[middle] > key: 33 | right = middle - 1 34 | if data[middle] < key: 35 | left = middle + 1 36 | if data[middle] == key: 37 | return middle 38 | return -1 39 | 40 | 41 | # NOTE Take a look at this method 42 | def test_binary_search(): 43 | binary_search_alg = [binary_search_iter, binary_search_rec] 44 | 45 | for bs_alg in binary_search_alg: 46 | data = list(range(1000)) 47 | for i in range(0, 1000): 48 | assert i == bs_alg(data, i) 49 | assert -1 == bs_alg(list(range(100)), 101) 50 | assert -1 == bs_alg(list(range(100)), -1) 51 | 52 | 53 | test_binary_search() 54 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar11/service/undo_service.py: -------------------------------------------------------------------------------- 1 | class FunctionCall: 2 | def __init__(self, functionName, *functionArguments): 3 | self.__functionName = functionName 4 | self.__functionArguments = functionArguments 5 | 6 | def call(self): 7 | self.__functionName(*self.__functionArguments) 8 | 9 | def __call__(self, *args, **kwargs): 10 | self.call() 11 | 12 | class Operation: 13 | def __init__(self, functionUndo, functionRedo): 14 | self.__functionUndo = functionUndo 15 | self.__functionRedo = functionRedo 16 | 17 | def undo(self): 18 | self.__functionUndo() 19 | 20 | def redo(self): 21 | self.__functionRedo() 22 | 23 | class UndoError(Exception): 24 | pass 25 | 26 | class CascadedOperation: 27 | def __init__(self, *operations): 28 | self.__operations = operations 29 | 30 | def undo(self): 31 | for op in self.__operations: 32 | op.undo() 33 | 34 | def redo(self): 35 | for op in self.__operations: 36 | op.redo() 37 | 38 | class UndoService: 39 | def __init__(self): 40 | self.__history = [] 41 | self.__index = -1 42 | 43 | def recordUndo(self, operation: Operation): 44 | self.__history.append(operation) 45 | self.__index = len(self.__history) - 1 46 | 47 | def undo(self): 48 | if self.__index == -1: 49 | raise UndoError("No more undos") 50 | self.__history[self.__index].undo() 51 | self.__index -= 1 52 | 53 | def redo(self): 54 | if self.__index == len(self.__history) - 1: 55 | raise UndoError("No more redos") 56 | 57 | self.__index += 1 58 | self.__history[self.__index].redo() -------------------------------------------------------------------------------- /src/lecture/examples/ex13_insertion_sort.py: -------------------------------------------------------------------------------- 1 | """ 2 | Insertion sort. An O(n^2) complexity algorithm 3 | """ 4 | 5 | 6 | def insertion_sort(data: list): 7 | for i in range(1, len(data)): 8 | val = data[i] 9 | j = i - 1 10 | while (j >= 0) and (data[j] > val): 11 | data[j + 1] = data[j] 12 | j = j - 1 13 | data[j + 1] = val 14 | return data 15 | 16 | 17 | """ 18 | Binary insertion sort 19 | Source: https://www.geeksforgeeks.org/binary-insertion-sort/ (code contributed by Mohit Gupta_OMG) 20 | """ 21 | 22 | 23 | def binary_search(arr, val, start, end): 24 | # we need to distinguish whether we should insert before or after the left boundary. imagine [0] is the last 25 | # step of the binary search and we need to decide where to insert -1 26 | if start == end: 27 | if arr[start] > val: 28 | return start 29 | else: 30 | return start + 1 31 | 32 | # this occurs if we are moving beyond left's boundary meaning the left boundary is the least position to find a 33 | # number greater than val 34 | if start > end: 35 | return start 36 | 37 | mid = (start + end) // 2 38 | if arr[mid] < val: 39 | return binary_search(arr, val, mid + 1, end) 40 | elif arr[mid] > val: 41 | return binary_search(arr, val, start, mid - 1) 42 | else: 43 | return mid 44 | 45 | 46 | def binary_insertion_sort(data: list): 47 | for i in range(1, len(data)): 48 | val = data[i] 49 | j = binary_search(data, val, 0, i - 1) 50 | # This is O(n) space complexity, but it can be simplified by moving elements one by one 51 | data = data[:j] + [val] + data[j:i] + data[i + 1:] 52 | return data 53 | -------------------------------------------------------------------------------- /src/lecture/examples/ex38_pickle_files.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | 3 | 4 | class Person: 5 | def __init__(self, person_id, family_name, given_name): 6 | self._personId = person_id 7 | self._familyName = family_name 8 | self._givenName = given_name 9 | 10 | @property 11 | def id(self): 12 | return self._personId 13 | 14 | @property 15 | def family_name(self): 16 | return self._familyName 17 | 18 | @property 19 | def given_name(self): 20 | return self._givenName 21 | 22 | def __str__(self): 23 | return str(self._personId) + " - " + self._familyName + " " + self._givenName 24 | 25 | 26 | def write_binary_file(file_name, persons): 27 | f = open(file_name, "wb") 28 | pickle.dump(persons, f) 29 | f.close() 30 | 31 | 32 | def read_binary_file(file_name): 33 | try: 34 | f = open(file_name, "rb") 35 | return pickle.load(f) 36 | except EOFError: 37 | """ 38 | This is raised if input file is empty 39 | """ 40 | return [] 41 | except IOError as e: 42 | """ 43 | Here we 'log' the error, and throw it to the outer layers 44 | """ 45 | print("An error occured - " + str(e)) 46 | raise e 47 | 48 | 49 | if __name__ == "__main__": 50 | """ 51 | Initialize a list of objects 52 | """ 53 | persons = [Person(1, "Pop", "Anca"), Person(2, "Morariu", "Sergiu"), Person(3, "Moldovean", "Iuliu")] 54 | 55 | """ 56 | Write it to a text file 57 | """ 58 | write_binary_file("persons.pickle", persons) 59 | 60 | """ 61 | Read it back and see what we have 62 | """ 63 | for p in read_binary_file("persons.pickle"): 64 | print(p) 65 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date, timedelta 2 | 3 | from seminar.group913.seminar_10.domain.client import Client 4 | from seminar.group913.seminar_9.domain.car import Car 5 | 6 | 7 | class Rental: 8 | def __init__(self, rental_id: int, start: date, end: date, client, car): 9 | self.__id = rental_id 10 | self.__client = client 11 | self.__car = car 12 | self.__start = start 13 | self.__end = end 14 | 15 | @property 16 | def id(self): 17 | return self.__id 18 | 19 | @property 20 | def client(self): 21 | return self.__client 22 | 23 | @property 24 | def car(self): 25 | return self.__car 26 | 27 | @property 28 | def start(self): 29 | return self.__start 30 | 31 | @property 32 | def end(self): 33 | return self.__end 34 | 35 | # len(rental) 36 | def __len__(self): 37 | if self.__end is not None: 38 | return (self.__end - self.__start).days + 1 39 | today = date.today() 40 | return (today - self.__start).days + 1 41 | 42 | def __repr__(self): 43 | return str(self) 44 | 45 | def __str__(self): 46 | # return 47 | from_date = self.__start.strftime("%Y-%m-%d") 48 | to_date = self.__end.strftime("%Y-%m-%d") 49 | return f"{self.id} - [car {self.car}] - [client {self.client}] - from {from_date} to {to_date}" 50 | 51 | 52 | if __name__ == "__main__": 53 | d1 = date(2020, 12, 15) 54 | d2 = date(2022, 12, 15) 55 | 56 | car = Car(100, "AB 01 ERT", "VW Tiguan") 57 | client = Client(200, "Popescu Marcel") 58 | rent = Rental(300, date(2024, 11, 30), date(2024, 12, 5), client, car) 59 | 60 | print(rent) 61 | -------------------------------------------------------------------------------- /src/seminar/group914/seminar_10/domain/rental.py: -------------------------------------------------------------------------------- 1 | from datetime import date, timedelta 2 | 3 | from seminar.group914.seminar_10.domain.client import Client 4 | from seminar.group914.seminar_9.domain.car import Car 5 | 6 | 7 | class Rental: 8 | def __init__(self, rental_id: int, start: date, end: date, client, car): 9 | self.__id = rental_id 10 | self.__client = client 11 | self.__car = car 12 | self.__start = start 13 | self.__end = end 14 | 15 | @property 16 | def id(self): 17 | return self.__id 18 | 19 | @property 20 | def client(self): 21 | return self.__client 22 | 23 | @property 24 | def car(self): 25 | return self.__car 26 | 27 | @property 28 | def start(self): 29 | return self.__start 30 | 31 | @property 32 | def end(self): 33 | return self.__end 34 | 35 | # len(rental) 36 | def __len__(self): 37 | if self.__end is not None: 38 | return (self.__end - self.__start).days + 1 39 | today = date.today() 40 | return (today - self.__start).days + 1 41 | 42 | def __repr__(self): 43 | return str(self) 44 | 45 | def __str__(self): 46 | # return 47 | from_date = self.__start.strftime("%Y-%m-%d") 48 | to_date = self.__end.strftime("%Y-%m-%d") 49 | return f"{self.id} - [car {self.car}] - [client {self.client}] - from {from_date} to {to_date}" 50 | 51 | 52 | if __name__ == "__main__": 53 | d1 = date(2020, 12, 15) 54 | d2 = date(2022, 12, 15) 55 | 56 | car = Car(100, "AB 01 ERT", "VW Tiguan") 57 | client = Client(200, "Popescu Marcel") 58 | rent = Rental(300, date(2024, 11, 30), date(2024, 12, 5), client, car) 59 | 60 | print(rent) 61 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar9/repository/carRepositoryInMemory.py: -------------------------------------------------------------------------------- 1 | from Seminar916.Seminar9.domain.car import Car, generateNRandomCars 2 | 3 | 4 | class RepositoryError(Exception): 5 | def __init__(self, msg: str): 6 | self.__msg = msg 7 | 8 | def __str__(self): 9 | return "Repository Exception: " + self.__msg 10 | 11 | class CarRepositoryInMemory: 12 | def __init__(self): 13 | self._data = {} 14 | 15 | def getAllCars(self): 16 | return list(self._data) 17 | 18 | def __len__(self): 19 | return len(list(self._data)) 20 | 21 | def addCar(self, car: Car): 22 | if car.licensePlate in self._data: 23 | raise RepositoryError("Car already exists") 24 | self._data[car.licensePlate] = car 25 | 26 | def removeCar(self, licensePlate: str) -> Car: 27 | if licensePlate not in self._data: 28 | raise RepositoryError("Car does not exist") 29 | 30 | car = self._data[licensePlate] 31 | del self._data[licensePlate] 32 | 33 | return car 34 | 35 | 36 | def testInMemoryRepository(): 37 | repo = CarRepositoryInMemory() 38 | repoLength = 0 39 | 40 | assert len(repo) == repoLength 41 | 42 | cars = generateNRandomCars(5) 43 | for i in range(5): 44 | repo.addCar(cars[i]) 45 | repoLength += 1 46 | 47 | assert len(repo) == repoLength 48 | 49 | try: 50 | repo.addCar(cars[0]) 51 | print("We have a problem") 52 | assert False 53 | except: 54 | print("Clear") 55 | assert True 56 | 57 | carToBeDeleted = cars[1] 58 | deletedCar = repo.removeCar(cars[1].licensePlate) 59 | assert deletedCar.licensePlate == carToBeDeleted.licensePlate 60 | 61 | testInMemoryRepository() -------------------------------------------------------------------------------- /src/seminar/group917/Seminar11/service/undo_service.py: -------------------------------------------------------------------------------- 1 | class FunctionCall: 2 | def __init__(self, functionName, *functionArgs): 3 | self.__functionName = functionName 4 | self.__functionParameters = functionArgs 5 | 6 | def call(self): 7 | self.__functionName(*self.__functionParameters) 8 | 9 | def __call__(self, *args, **kwargs): 10 | return self.call() 11 | 12 | class Operation: 13 | def __init__(self, functionUndo, functionRedo): 14 | self.__functionUndo = functionUndo 15 | self.__functionRedo = functionRedo 16 | 17 | def undo(self): 18 | self.__functionUndo() 19 | 20 | def redo(self): 21 | self.__functionRedo() 22 | 23 | class CascadedOperation: 24 | def __init__(self, *operations): 25 | self.__operations = operations 26 | 27 | def undo(self): 28 | for op in self.__operations: 29 | op.undo() 30 | 31 | def redo(self): 32 | for op in self.__operations: 33 | op.redo() 34 | 35 | class UndoError(Exception): 36 | pass 37 | 38 | class UndoService: 39 | def __init__(self): 40 | self.__history = [] 41 | self.__index = -1 42 | 43 | def recordUndo(self, operation: Operation): 44 | self.__history.append(operation) 45 | self.__index = len(self.__history) - 1 46 | 47 | def undo(self): 48 | if self.__index == -1: 49 | raise UndoError("No more undos available") 50 | 51 | self.__history[self.__index].undo() 52 | self.__index -= 1 53 | 54 | def redo(self): 55 | if self.__index == len(self.__history) - 1: 56 | raise UndoError("No more redos available") 57 | 58 | self.__index += 1 59 | self.__history[self.__index].redo() 60 | -------------------------------------------------------------------------------- /src/seminar/group916/Seminar11/service/undo_service.py: -------------------------------------------------------------------------------- 1 | class FunctionCall: 2 | def __init__(self, functionName, *functionParamteres): 3 | self.__functionName = functionName 4 | self.__functionParameters = functionParamteres 5 | 6 | def call(self): 7 | self.__functionName(*self.__functionParameters) 8 | 9 | def __call__(self, *args, **kwargs): 10 | return self.call() 11 | 12 | class Operation: 13 | def __init__(self, functionUndo, functionRedo): 14 | self.__functionUndo = functionUndo 15 | self.__functionRedo = functionRedo 16 | 17 | def undo(self): 18 | self.__functionUndo() 19 | 20 | def redo(self): 21 | self.__functionRedo() 22 | 23 | class CascadedOperation: 24 | def __init__(self, *operations): 25 | self.__operations = operations 26 | 27 | def undo(self): 28 | for oper in self.__operations: 29 | oper.undo() 30 | 31 | def redo(self): 32 | for oper in self.__operations: 33 | oper.redo() 34 | 35 | class UndoError(Exception): 36 | pass 37 | 38 | class UndoService: 39 | def __init__(self): 40 | self.__history = [] 41 | self.__index = -1 42 | 43 | def recordUndo(self, operation: Operation): 44 | self.__history.append(operation) 45 | self.__index = len(self.__history) - 1 46 | 47 | def undo(self): 48 | if self.__index == -1: 49 | raise UndoError("No more undos") 50 | 51 | self.__history[self.__index].undo() 52 | self.__index -= 1 53 | 54 | def redo(self): 55 | if self.__index == len(self.__history) - 1: 56 | raise UndoError("No more redos") 57 | 58 | self.__index += 1 59 | self.__history[self.__index].redo() 60 | 61 | -------------------------------------------------------------------------------- /src/seminar/group913/seminar_10/service/rental_service.py: -------------------------------------------------------------------------------- 1 | from seminar.group913.seminar_10.domain.rental import Rental 2 | from seminar.group913.seminar_10.repository.memory_repo import MemoryRepository 3 | from seminar.group913.seminar_9.domain.car import Car 4 | 5 | 6 | class CarPopularityDTO: # DTO - data transfer object 7 | def __init__(self, car: Car, client_count: int): 8 | self.__car = car 9 | self.__client_count = client_count 10 | 11 | @property 12 | def car(self): 13 | return self.__car 14 | 15 | @property 16 | def clients(self): 17 | return self.__client_count 18 | 19 | def __lt__(self, other): 20 | return self.__client_count > other.__client_count 21 | 22 | 23 | class RentalService: 24 | def __init__(self, repo: MemoryRepository, car_repo: MemoryRepository): 25 | self._repo = repo 26 | self.__car_repo = car_repo 27 | 28 | def get(self, rental_id: int) -> Rental: 29 | return self._repo[rental_id] 30 | 31 | def most_popular_cars(self) -> [CarPopularityDTO]: 32 | """ 33 | Return a list of cars with the number of distinct clients that have rented it. 34 | :return: 35 | """ 36 | car_client_ids = {} # dicts should have immutable objects as keys 37 | 38 | for rental in self._repo: 39 | if rental.car.id not in car_client_ids: 40 | car_client_ids[rental.car.id] = {rental.client.id} 41 | else: 42 | car_client_ids[rental.car.id].add(rental.client.id) 43 | 44 | result = [] 45 | for car_id in car_client_ids: 46 | result.append(CarPopularityDTO(self.__car_repo.find(car_id), len(car_client_ids[car_id]))) 47 | result.sort() 48 | return result 49 | -------------------------------------------------------------------------------- /src/lecture/livecoding/lecture_7/calc.py: -------------------------------------------------------------------------------- 1 | from lecture.livecoding.lecture_7.rational_as_list import create_rational, add_rational 2 | # NOTE We import the same functions twice to show how Python handles the import statement. 3 | # Generally speaking this is bad practice 4 | from lecture.livecoding.lecture_7.rational_as_dict import create_rational, add_rational 5 | 6 | 7 | def create_calc(): 8 | """ 9 | Create a calculator with a default value 10 | 11 | :return: The calculator initialized with the default value of 0 12 | """ 13 | return {"value": create_rational(0), "history": []} 14 | 15 | 16 | def get_calc_value(calculator): 17 | return calculator["value"] 18 | 19 | 20 | def _set_calc_value_internal(calculator, q): 21 | # set the new calculator value 22 | calculator["value"] = q 23 | 24 | 25 | def set_calc_value(calculator, q): 26 | # append the old calculator value to the list 27 | calculator["history"].append(calculator["value"]) 28 | _set_calc_value_internal(calculator, q) 29 | 30 | 31 | def add_calculator(calculator, q) -> None: 32 | """ 33 | Add a rational number to the calculator 34 | 35 | :param calculator: The calculator's current state 36 | :param q: The number to add 37 | """ 38 | current_value = get_calc_value(calculator) 39 | new_value = add_rational(current_value, q) 40 | set_calc_value(calculator, new_value) 41 | 42 | 43 | def undo_calculator(calculator) -> None: 44 | if len(calculator["history"]) == 0: 45 | # NOTE ValueError is perhaps not fitting here but we don't know other exceptions ... yet :( 46 | raise ValueError("Undo not available") 47 | last_value = calculator["history"].pop() 48 | # set_calc_value(calculator, last_value) 49 | _set_calc_value_internal(calculator, last_value) 50 | -------------------------------------------------------------------------------- /src/seminar/group915/Seminar9/repository/carsRepositoryInMemory.py: -------------------------------------------------------------------------------- 1 | from Seminar915.Seminar9.domain.car import Car, generateNRandomCars 2 | 3 | 4 | class RepositoryError(Exception): 5 | def __init__(self, msg: str): 6 | self.__msg = msg 7 | 8 | def __str__(self): 9 | return "Repository Exception: " + self.__msg 10 | 11 | class CarRepositoryInMemory: 12 | def __init__(self): 13 | self._data = {} 14 | 15 | def getAllCars(self): 16 | return list(self._data) 17 | 18 | def addCar(self, car: Car): 19 | if car.getLicensePlate() in self._data: 20 | raise RepositoryError("Car already exists") 21 | self._data[car.getLicensePlate()] = car 22 | 23 | def removeCar(self, licensePlate: str) -> Car: 24 | if licensePlate not in self._data: 25 | raise RepositoryError("Car does not exist") 26 | 27 | car = self._data[licensePlate] 28 | del self._data[licensePlate] 29 | return car 30 | 31 | def __len__(self): 32 | return len(list(self._data)) 33 | 34 | def testInMemory(): 35 | repo = CarRepositoryInMemory() 36 | repo_len = 0 37 | 38 | assert len(repo) == repo_len 39 | 40 | cars = generateNRandomCars(5) 41 | for i in range(len(cars)): 42 | repo.addCar(cars[i]) 43 | repo_len += 1 44 | 45 | assert len(repo) == repo_len 46 | 47 | try: 48 | repo.addCar(cars[0]) 49 | repo_len += 1 50 | assert False 51 | except: 52 | assert len(repo) == repo_len 53 | 54 | carToDelete = cars[1] 55 | deletedCar = repo.removeCar(carToDelete.getLicensePlate()) 56 | repo_len -= 1 57 | 58 | assert len(repo) == repo_len 59 | assert carToDelete.getLicensePlate() == deletedCar.getLicensePlate() 60 | 61 | testInMemory() 62 | 63 | --------------------------------------------------------------------------------