Learn Python The Hard Way learning (11)-Question

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.