Stupid Methodology Python Exercise 5: More variables and print __python

Source: Internet
Author: User

#!usr/bin/python #-*-Coding:utf8-*-my_name = "Zed A. Shaw" my_age= #not a lie my_height = #inches My_weight = 180 #lbs My_eyes = "Blue" My_teeth = "white" My_hair = "Brown" Print ("Let ' s talk about%s."% my_name) print ("The He's%d I Nches tall. "% my_height" print ("He's%d pounds heavy."% my_weight) print ("Actually that's not too heavy.") Print ("he"

S got%s eyes and%s hair.% (My_eyes, My_hair)) print ("his teeth are usually%s depending on the coffee."% My_teeth) # this are tricky, try to get it ecactly riht print (' If I add%d,%d, and%d I get%d '% (My_age, My_height, M 
Y_weight, My_age + my_height + my_weight)) print ("---------------------------------------------") name = "Zed A. Shaw"  Age= #not a Lie height = #inches weight = 180 #lbs eyes = "Blue" teeth = "white" hair = "Brown" Print ("Let ' s talk About%s.% Name Print ("He '%d inches tall."% height) print ("The He's%d pounds heavy."% weight) print ("actually that
' s not too heavy. ') PrinT ("He's got%s eyes and%s hair."% (eyes, hair)) print ("his teeth are usually%s depending on the coffee."% teeth) # This are tricky, try to get it ecactly riht print ("If I add%d,%d, and%d I get%d."% (age, height, weight,  Age + height + weight)

The results of the operation are as follows:

$ python ex5.py let
' s talk about Zed A. Shaw.
He's inches tall.
He ' s 180 pounds heavy.
Actually that ' s not too heavy.
He ' s got Blue eyes and Brown hair.
His teeth are usually white depending on the coffee.
If I add, and 180 I get 289.
$

Add points Exercise

Modify all the variable names and remove the ' my_ ' in front of them. Be sure to get rid of every place, not just where you use the ' = ' assignment.

Try to use more formatting characters. For example,%r is a very useful one, meaning "print whatever it is".

Search the web for all the Python formatting characters.

Try using variables to convert inches and pounds into centimeters and kilograms. Do not type the answer directly. Use Python's computational capabilities to do this.


Answers to common questions

This defines the variable line: 1 = ' Zed Shaw '?

No way. 1 is not a valid variable name. Variable names begin with a letter. So A1 can, but 1 not.

%s,%r,%d What do these symbols mean?

Later you will learn more in detail, and now you can tell you that they are a "format control tool." They tell Python to take the variable on the right to the string and place the value of the variable in the location of%s.

Still don't understand, "format Control tool" is what?

To understand the meaning of a description, you have to learn to program before it is easier to understand, you can write down this question, see if the later content will explain these things to you.

How do I round floating points?

You can use the round () function, for example: round (1.7333)

I ran into a mistake: typeerror: ' str ' object is not callable.

It is very likely that you are missing the% between the string and the variable.

What's all this stuff? I'm still confused.

It would be strange to try to think of the numbers in the script as something you have measured out of yourself, but it will give you a sense of being immersive and help you understand something.


Related Article

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.