####################### Programming with Python ####################### .. toctree:: :hidden: introduction_to_python/index exercises/index examples/index pythonic_specialities/index introduction_to_command_line_shells/index references .. image:: /_static/programming_with_python/python-logo.png .. admonition:: Precap Python has the reputation of being a comparatively easy to learn programming language. The objective of this course is to develop basic programming skills using the `Python 3 `__ programming language. It is split into several sections, each with a focus on a different aspect of programming with Python. The sections are: .. rst-class:: strong-references * :doc:`introduction_to_python/index`: An introduction to the fundamental elements of the programming language. * :doc:`exercises/index`: Scripts that focus on fundamental topics like data types, calculations, conditions, loops, functions, etc. * :doc:`examples/index`: Scripts that demonstrate real-world applications using external libraries, internet communication, graphical user interfaces, etc. * :doc:`pythonic_specialities/index`: Most of the fundamental elements are shared across all programming languages, but some are special to Python. * :doc:`introduction_to_command_line_shells/index`: An introduction to a text-based and very common way to interact with a program. * :doc:`references`: ... .. /physical_computing/introduction_to_python/index /physical_computing/introduction_to_python/first_steps .. table:: :class: lecture-directory :width: 100% :widths: 10 80 10 +------+--------+----------------------------------+ | | Read | Watch | +======+========+==================================+ | *Common electronic circuits* | +------+--------+----------------------------------+ | *Introduction* | +------+--------+----------------------------------+ | TX10 | |TX00| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX01| | 12’22” | +------+--------+----------------------------------+ | TX10 | |TX02| | 12’22” | +------+--------+----------------------------------+ | *Basic Examples* | +------+--------+----------------------------------+ | TX10 | |TX20| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX21| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX22| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX23| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX24| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX25| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX26| | 12’22” | +------+--------+----------------------------------+ | *Advanced Examples* | +------+--------+----------------------------------+ | TX11 | |TX30| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX31| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX32| | 12’22” | +------+--------+----------------------------------+ | TX11 | |TX33| | 12’22” | +------+--------+----------------------------------+ .. |TX00| replace:: `Prerequisites `__ |br| System requirements software download and installation. .. |TX01| replace:: `Using a command-line interface (CLI) `__ |br| A quick introduction to how to use the built in CLIs on your computer. .. |TX02| replace:: `Elements of a programming language `__ |br| Reserved words, identifiers, and everything else. .. |TX20| replace:: `Reserved words and identifiers `__ |br| Hello, world! .. |TX21| replace:: `Data types `__ |br| Numbers, texts, lists, dictionaries and tuples. .. |TX22| replace:: `Conditions <./basic_examples/2-conditions_and_loops>`__ |br| Skip lines of code under certain conditions. .. |TX23| replace:: `Loops `__ |br| Repeat lines of code multiple times. .. |TX24| replace:: `Functions `__ |br| Name lines of code to improve modularity and reusability. .. |TX25| replace:: `Classes `__ |br| Name a group of variables and functions and use them as a blueprint. .. |TX26| replace:: `Exceptions `__ |br| Anticipating and catching errors. .. |TX30| replace:: `Internet communication & data interchange formats `__ |br| Getting weather information from https://openweathermap.org. .. |TX31| replace:: `Speak and listen `__ |br| Convert text to speech and speech to text .. |TX32| replace:: `Graphical user interfaces (GUIs) `__ |br| Create a stop watch or analogue clock with the Tkinter library. .. |TX33| replace:: `Lights on `__ |br| Control Philips Hue lights with Python. .. +-----+--------------------------------------------------------------+--------------------------------------------+ | # | Title | Topics | +=====+==============================================================+============================================+ | 0/9 | **Introduction** | + +--------------------------------------------------------------+--------------------------------------------+ | | `01-print.py`_ | print(), string literal | + +--------------------------------------------------------------+--------------------------------------------+ | | `02-print_w_special_character.py`_ | special characters | + +--------------------------------------------------------------+--------------------------------------------+ | | `03-print_w_variable.py`_ | variables | + +--------------------------------------------------------------+--------------------------------------------+ | | `04-for_loops.py`_ | lists, loop | + +--------------------------------------------------------------+--------------------------------------------+ | | `05-for_loops_and_conditions.py`_ | conditions | + +--------------------------------------------------------------+--------------------------------------------+ | | `06-calculations_and_types.py`_ | operators, types | + +--------------------------------------------------------------+--------------------------------------------+ | | `07-functions.py`_ | functions | +-----+--------------------------------------------------------------+--------------------------------------------+ | 1/9 | **Reserved words and identifiers** | + +--------------------------------------------------------------+--------------------------------------------+ | | `11-hello_world.py`_ | print(), string literal | + +--------------------------------------------------------------+--------------------------------------------+ | | `12-hello_world_w_variable.py`_ | variable, =, + | + +--------------------------------------------------------------+--------------------------------------------+ | | `13-hello_world_w_input.py`_ | input() | + +--------------------------------------------------------------+--------------------------------------------+ | | `14-hello_world_w_pythonic_string_formatting.py`_ | str.format() | + +--------------------------------------------------------------+--------------------------------------------+ | | `15-celsius_to_fahrenheit.py`_ | int(), \*, / | + +--------------------------------------------------------------+--------------------------------------------+ | | `16-celsius_to_fahrenheit_w_pythonic_string_formatting.py`_ | if, else, %, == | +-----+--------------------------------------------------------------+--------------------------------------------+ | 2/9 | **Conditions and loops** | + +--------------------------------------------------------------+--------------------------------------------+ | | `21-even_or_odd_number.py`_ | True, //, for, in, range(), False, break | + +--------------------------------------------------------------+--------------------------------------------+ | | `22-is_prime_number.py`_ | | + +--------------------------------------------------------------+--------------------------------------------+ | | `23-mean_number.py`_ | str.split(), float(), len() | + +--------------------------------------------------------------+--------------------------------------------+ | | `24-mean_number_w_library.py`_ | from, import, statistics.mean | +-----+--------------------------------------------------------------+--------------------------------------------+ | 3/9 | **Lists, Dictionaries and Tuples** | + +--------------------------------------------------------------+--------------------------------------------+ | | `31-weekdays.py`_ | lists | + +--------------------------------------------------------------+--------------------------------------------+ | | `31q-months.py`_ | lists (Quiz) | + +--------------------------------------------------------------+--------------------------------------------+ | | `32-days_per_month.py`_ | dictionaries | +-----+--------------------------------------------------------------+--------------------------------------------+ | 4/9 | **Functions** | + +--------------------------------------------------------------+--------------------------------------------+ | | `41-is_prime_number_redundant.py`_ | functions | + +--------------------------------------------------------------+ + | | `42-is_prime_number_w_function.py`_ | | + +--------------------------------------------------------------+ + | | `43-rectangle.py`_ | | + +--------------------------------------------------------------+ + | | `44-shapes.py`_ | | + +--------------------------------------------------------------+--------------------------------------------+ | | `44q-shapes.py`_ | functions (Quiz) | + +--------------------------------------------------------------+--------------------------------------------+ | | `45-variable_scope.py`_ | Variable scope | +-----+--------------------------------------------------------------+--------------------------------------------+ | 5/9 | **Classes** | + +--------------------------------------------------------------+--------------------------------------------+ | | `51-two_rectangles.py`_ | classes | + +--------------------------------------------------------------+ + | | `52-shapes.py`_ | | + +--------------------------------------------------------------+--------------------------------------------+ | | `52q-shapes.py`_ | classes (Quiz) | +-----+--------------------------------------------------------------+--------------------------------------------+ | 6/9 | **Internet communication** | + +--------------------------------------------------------------+--------------------------------------------+ | | `61-yahoo_weather_w_urllib.py`_ | HTTP requests, JSON parsing | + +--------------------------------------------------------------+ + | | `62-yahoo_weather_w_urllib3.py`_ | | + +--------------------------------------------------------------+ + | | `63-yahoo_weather_w_requests.py`_ | | +-----+--------------------------------------------------------------+--------------------------------------------+ | 7/9 | **Philips Hue** | + +--------------------------------------------------------------+--------------------------------------------+ | | `71-philips_hue_blink.py`_ | RESTful web services, Philips Hue API | + +--------------------------------------------------------------+ + | | `72-philips_hue_fade.py`_ | | + +--------------------------------------------------------------+ + | | `73-philips_hue_sweep.py`_ | | +-----+--------------------------------------------------------------+--------------------------------------------+ | 8/9 | **Google Speech** | + +--------------------------------------------------------------+--------------------------------------------+ | | `81-text_to_speech.py`_ | | + +--------------------------------------------------------------+ + | | `82-the_time_is.py`_ | | + +--------------------------------------------------------------+ + | | `83-the_time_is_multilingual.py`_ | | + +--------------------------------------------------------------+ + | | `84_speech_to_text.py`_ | | + +--------------------------------------------------------------+ + | | `85_speech_to_text_multilingual.py`_ | | +-----+--------------------------------------------------------------+--------------------------------------------+ | 9/9 | **Graphical user interfaces** | +-----+--------------------------------------------------------------+--------------------------------------------+ | | `91-window_w_label.py`_ | tkinter | + +--------------------------------------------------------------+ + | | `92-window_w_button.py`_ | | + +--------------------------------------------------------------+ + | | `93-window_w_frame.py`_ | | + +--------------------------------------------------------------+ + | | `94-window_w_subclassed_frame.py`_ | | + +--------------------------------------------------------------+ + | | `95-stop_watch.py`_ | | + +--------------------------------------------------------------+ + | | `96-stop_watch_w_lap_time.py`_ | | + +--------------------------------------------------------------+ + | | `97-traffic_light.py`_ | | + +--------------------------------------------------------------+ + | | `98q-analogue_clock.py`_ | | +-----+--------------------------------------------------------------+--------------------------------------------+ | | **Additional Examples** | + +--------------------------------------------------------------+--------------------------------------------+ | | `persistence_of_a_number.py`_ | functions, measuring process time | +-----+--------------------------------------------------------------+--------------------------------------------+ | | `References`_ | Downloads, Tutorials (Online) | +-----+--------------------------------------------------------------+--------------------------------------------+ .. _Introduction: 0-introduction/index.html .. _01-print.py: examples/0-introduction/index.html#print-py .. _02-print_w_special_character.py: examples/0-introduction/index.html#print-w-special-character-py .. _03-print_w_variable.py: examples/0-introduction/index.html#print-w-variable-py .. _04-for_loops.py: examples/0-introduction/index.html#for-loops-py .. _05-for_loops_and_conditions.py: examples/0-introduction/index.html#for-loops-and-conditions-py .. _06-calculations_and_types.py: examples/0-introduction/index.html#calculations-and-types-py .. _07-functions.py: examples/0-introduction/index.html#functions-py .. _Reserved words and identifiers: 1-reserved_words_and_identifiers/index.html .. _11-hello_world.py: examples/1-reserved_words_and_identifiers/index.html#hello-world-py .. _12-hello_world_w_variable.py: examples/1-reserved_words_and_identifiers/index.html#hello-world-w-variable-py .. _13-hello_world_w_input.py: examples/1-reserved_words_and_identifiers/index.html#hello-world-w-input-py .. _14-hello_world_w_pythonic_string_formatting.py: examples/1-reserved_words_and_identifiers/index.html#hello-world-w-pythonic-string-formatting-py .. _15-celsius_to_fahrenheit.py: examples/1-reserved_words_and_identifiers/index.html#celsius-to-fahrenheit-py .. _16-celsius_to_fahrenheit_w_pythonic_string_formatting.py: examples/1-reserved_words_and_identifiers/index.html#celsius-to-fahrenheit-w-pythonic-string-formatting-py .. _Conditions and loops: 2-conditions_and_loops/index.html .. _21-even_or_odd_number.py: examples/2-conditions_and_loops/index.html#even-or-odd-number-py .. _22-is_prime_number.py: examples/2-conditions_and_loops/index.html#is-prime-number-py .. _23-mean_number.py: examples/2-conditions_and_loops/index.html#mean-number-py .. _24-mean_number_w_library.py: examples/2-conditions_and_loops/index.html#mean-number-w-library-py .. _Lists, Dictionaries and Tuples: 3-lists_dictionaries_and_tuples.html .. _31-weekdays.py: examples/3-lists_dictionaries_and_tuples/index.html#weekdays-py .. _31q-months.py: examples/3-lists_dictionaries_and_tuples/index.html#q-months-py .. _32-days_per_month.py: examples/3-lists_dictionaries_and_tuples/index.html#days-per-month-py .. _Functions: 4-functions/index.html .. _41-is_prime_number_redundant.py: examples/4-functions/index.html#is-prime-number-redundant-py .. _42-is_prime_number_w_function.py: examples/4-functions/index.html#is-prime-number-w-function-py .. _43-rectangle.py: examples/4-functions/index.html#rectangle-py .. _44-shapes.py: examples/4-functions/index.html#shapes-py .. _44q-shapes.py: examples/4-functions/index.html#q-shapes-py .. _45-variable_scope.py: examples/4-functions/index.html#variable-scope-py .. _Classes: 5-classes/index.html .. _51-two_rectangles.py: examples/5-classes/index.html#two-rectangles-py .. _52-shapes.py: examples/5-classes/index.html#shapes-py .. _52q-shapes.py: examples/5-classes/index.html#q-shapes-py .. _Internet communication: 6-internet_communication/index.html .. _61-yahoo_weather_w_urllib.py: examples/6-internet_communication/index.html#yahoo-weather-w-urllib-py .. _62-yahoo_weather_w_urllib3.py: examples/6-internet_communication/index.html#yahoo-weather-w-urllib3-py .. _63-yahoo_weather_w_requests.py: examples/6-internet_communication/index.html#yahoo-weather-w-requests-py .. _Philips Hue: 7-philips_hue/index.html .. _71-philips_hue_blink.py: examples/7-philips_hue/index.html#philips-hue-blink-py .. _72-philips_hue_fade.py: examples/7-philips_hue/index.html#philips-hue-fade-py .. _73-philips_hue_sweep.py: examples/7-philips_hue/index.html#philips-hue-sweep-py .. _Google Speech: 8-google_speech/index.html .. _81-text_to_speech.py: examples/8-google_speech/index.html#text-to-speech-py .. _82-the_time_is.py: examples/8-google_speech/index.html#the-time-is-py .. _83-the_time_is_multilingual.py: examples/8-google_speech/index.html#the-time-is-multilingual-py .. _84_speech_to_text.py: examples/8-google_speech/index.html#speech-to-text-py .. _85_speech_to_text_multilingual.py: examples/8-google_speech/index.html#speech-to-text-multilingual-py .. _Graphical user interfaces: 9-graphical_user_interfaces/index.html .. _91-window_w_label.py: examples/9-graphical_user_interfaces/index.html#window-w-label-py .. _92-window_w_button.py: examples/9-graphical_user_interfaces/index.html#window-w-button-py .. _93-window_w_frame.py: examples/9-graphical_user_interfaces/index.html#window-w-frame-py .. _94-window_w_subclassed_frame.py: examples/9-graphical_user_interfaces/index.html#window-w-subclassed-frame-py .. _95-stop_watch.py: examples/9-graphical_user_interfaces/index.html#simple-stop-py .. _96-stop_watch_w_lap_time.py: examples/9-graphical_user_interfaces/index.html#stop-watch-w_lap_time_py .. _97-traffic_light.py: examples/9-graphical_user_interfaces/index.html#traffic-light-py .. _98q-analogue_clock.py: examples/9-graphical_user_interfaces/index.html#q-analogue-clock-py .. _Additional Examples: 10-additional_examples/index.html .. _persistence_of_a_number.py: examples/10-additional_examples/index.html#persistence-of-a-number-py .. _References: references.html .. include:: /_includes/shell_commands.rst .. include:: /_includes/reserved_words.rst .. include:: keywords.rst