As promised in the previous class, I present to you this lesson about variables. First we need to answer some questions. First, what’s a variable? The answer is: a variable is a space inside a memory, it save data and in programming languages, it also works for change the data inside it. Python is an high-level language, an high-level language is nearer of programmer, or human language like English for example. Python is simple! See below the variable declaration in languages like C, C++ or Java: This is the variable declaration structure, but in Python, we don’t need of this structure. So, declare the type isn’t required, but we need to initializer the variable. Below, see the variable declaration structure in Python: That’s enough, here we have the variable declaration in Python language. This structure is: variable_name = a_value, it can be a string too, or just a character. Test it in your interpreter, joyful! If you want to use other...
As I said in the previous lesson, Access Here , I have to you 5 challenges to you practice your ability. 1- Make an algorithm that ask to user type numbers, the stop condition is when was typed the Number 0, say to user the stop condition. 2- Make an algorithm that aks to user many numbers, use the stop condition, when the user type 0, so print the sum result at display. 3- Make an algorithm that ask to user type a number and so use a do while to decrement this number up to 0. print them at display. 4- Make an algorithm that ask to user a number, you’ll multiplies by its predecessor up it be 0. Print all the process. 5- Make an algorithm that as to user letter, user the variable different of space character as condition. In the next lesson, we’ll see the Command While. Share it with your friends! Well, that’s all folks! See you later!
Now, do these Algorithms using switch command. 1- Make an algorithm that works as a game, it may ask to user “What’s United Kingdom Capital?” so the user will have available 4 possibility, they’re respectively a) Manchester, b) Newcastle, c) London, d) Liverpool, after will be tested them. Note: use for store the result, a character type variable. Case ‘c’, so printf (“You’re Wright”); default, so printf (“You’re wrong”); 2- Make an algorithm that reserves the product code and the quantity, so calculate the prices. Note: before defines how you can see below: ‘ M’ – Milk – U$ 1,00 1L. ‘ P’ – Potato – U$ 2,50 Kg. ‘ E’ – Meat – U$ 10,00 Kg. ‘ J’ – Juice – U$ 0,50 each. Use switch structure, for invalid values, use default to show a note at display. After multiple the price by quantity and print the total price. 3- Make an algorithm that works how a calculator. Use a char variable to store the operator and so make the operation and show...
Comentários
Postar um comentário