diff --git a/assets/flowchart_while_01.png b/assets/flowchart_while_01.png new file mode 100644 index 0000000..8afbcc0 Binary files /dev/null and b/assets/flowchart_while_01.png differ diff --git a/learning_python3.md b/learning_python3.md index 6778473..e9d8590 100644 --- a/learning_python3.md +++ b/learning_python3.md @@ -65,6 +65,22 @@ TODO animated overview of the shell and the world of OOP # Installing pycharm +Depending on the platform you use, you can install Pycharm in multiple ways. +The computers in the classroom come with Pycharm installed but if you want to continue working from home you can follow the instructions [here](https://www.jetbrains.com/pycharm/download/#section=windows). + +If you run Windows at home you will probably need to install python as well. +Download the latest version from [here](https://www.python.org/downloads/). +On Linux and Mac OSX there will probably be some version of python installed. +From a terminal you can check the version that's installed by executing the following commmands. + +```bash +waldek@metal:~$ python3 --version +Python 3.9.2 +waldek@metal:~$ +``` + +## Virtual environments + TODO # Your first project @@ -209,7 +225,7 @@ But how can we **get** some information from the user? This is done with the built-in `input` function. If we open up a python shell we can observe it's behaviour. -```python3 +```python >>> input() hello world 'hello world' @@ -436,7 +452,7 @@ You should do this in a **new** python file. I suggest you call it `c_to_f.py` or something that makes sense to you. The result of this program *could* be as follows. -```bash +``` ➜ ~ git:(master) ✗ python3 ex_celcius_to_fahrenheit.py What's the temperature?30 30°C equals 86.0°F @@ -1184,19 +1200,17 @@ while counter <= 10: print("after the loop, counter: {}".format(counter)) ``` -
- Another example + +Or with only variables and a more verbose way of incrementing the numbers. ```python3 -FirstValue = 2 -SecondValue = 0 -while FirstValue>SecondValue: - print("The second value is bigger") - SecondValue = SecondValue + 1 +first_value = 20 +second_value = 0 +while first_value > second_value: + print("second value {} is smaller than {}".format(second_value, first_value)) + second_value = second_value + 1 ``` -
- Two *extra* things might look new to you here. First the `import time` and `time.sleep(1)`, can you tell me what it does? Next the `counter += 1` which is called [incrementing](https://stackoverflow.com/questions/1485841/behaviour-of-increment-and-decrement-operators-in-python). @@ -1247,12 +1261,17 @@ print("after the loop, counter: {}".format(counter)) Infinite loops are a cornerstone of modern programming. While they might look scary, don't overthink it, you'll get used to them very quickly. +Logical procedures can be drawn out with flow charts. +An example can be seen in the image below. + +[flowchart while loop](./assets/flowchart_while_01.png) + ⛑ **When testing out an infinite loop it's sometimes handy to insert a `time.sleep` in it to slow down the execution a bit so you can wrap your head around what's happening.** 🏃 Try it --- -Go back to the Celsius to Farenheit converter and add a while loop to ensure the user puts in only numbers. +Go back to the Celsius to Fahrenheit converter and add a while loop to ensure the user puts in only numbers. # Coding challenge - Guess the number