We have seen this example previously. There I included a lot of loops to handle user input and the main logic… Now it is time to refactor the application to use functions. This should make the code readable and we could re-use parts later. [Read more…]
Now we have learned the basics of Python programming: variables, collections and loops. If you have followed the examples and the tutorial you might feel that sometimes we use too much code and it can be leveraged a bit. But maybe you do not know how to do it.
Most of the time the solution is to introduce functions. We have encountered functions of other modules which we used just like isupper() of strings or choice() of the random module.
If you have learned mathematics then you know about functions already. Mathematicians can do very nasty things with them but programmers too. The aim of a function is to produce a result which is determined only by the parameters passed to the function. [Read more…]
Now let’s write a script which implements a basic “Guess the number” game. The rules of the game are: [Read more…]
Loops allow to loop through the program code and repeat blocks of code until a given condition is fulfilled or not fulfilled. The code which is repeated is called the loop’s body.
Python has two types of loops: the for loop and the while loop. [Read more…]
Decision making with conditionals
After this vast amount of introductory articles with the basic types of variables in Python 3 it is time to go on and introduce conditional operators which help us create an application flow based on different conditions at runtime. [Read more…]