Python 2.1.2 : Basic Concept Part 2
We will explain these concepts through the cooking of an omelette: Cooking recipe: Break 4 eggs Mix Add cream If I have cheese: Add cheese Mix Cook for 5 minutes And we as developers, we have to write the recipe which is actually our source code so the cook will take the recipe and will realize it by executing the code. But there can be errors and the code does not behave as it should, we will try to understand the errors by debugging them. If we go back to our recipe, we can see that we have the numbers, which correspond to the variables for example; we have number of eggs which corresponds to 4 in reality we talk about assignment and it means that I will store 4 in number of eggs. To make it simple we can ask the number of people to the user and calculate the number of eggs knowing that a person eats 2 eggs we have number_eggs = number_person * 2 that's the interest of having the variables. We can have variables of type string like cheese and cream; which we can think of a variable: ingredient = "cheese". Then we have functions, you see we have actions like Break, Mix, Add, Cook and functions allow you to group several lines of code. We also have conditions: if I have cheese then : Add cheese otherwise : do nothing and in programming it is the if and else. Concerning the loops we can write a function Break_Eggs( ) and put the action break_an_egg 4 times. But this does not fit in function.