Now let's speed up our step. We have learned a lot of boring printing before. Next we will learn how to input information into our program. The following exercises may be a bit difficult, but believe me, just do it first and you will know what is going on later.
Most software tasks are:
• Receive user input
• Change input information
• Print the changed information
We only printed the above information. Below we implement simple input. The specific principle is explained in the next exercise.
[Python]
1. print "How old are you? ",
2. age = raw_input ()
3. print "How tall are you? ",
4. height = raw_input ()
5. print "How much do you weight? ",
6. weight = raw_input ()
7.
8.
9. print "So, you're % r old, % r tall and % r heavy." % (
10. age, height, weight)
Tip: we add a comma after each line, so that the line breaks will not wait for the input.
Running result
How old are you? 26
How tall are you? 6'2"
How much do you weight? 175 kg
So, you're '26' old, '6 \ '2 "'Tall and '20140901' heavy.
Extra score exercise
1. Find out what raw_input does online?
Read the string entered by a row.
2. Can you find other usage of it?
Age = raw_input ("How old are you? ")
3. Make some questions by yourself in the example above. Www.2cto.com
4. Let's take a look at the '6 \ '"' in the example. Here, the single quotation mark is escaped to prevent this single quotation mark from being considered an ending character.
Author: lixiang0522