Python learns "dumb ways to Learn Python" (supplemented with books)

Source: Internet
Author: User

Exercise 3: Numerical and mathematical calculations

There are a lot of mathematical arithmetic symbols in this chapter. Let's see what they are called. You have to read out their names while you write, until you are bored. The names are as follows:

+ Plus Plus
-Minus minus
/Slash Slash
* Asterisk asterisk
% percent percent percent
< Less-than, less than
> Greater-than greater than sign
<= less-than-equal less than equals sign
>= greater-than-equal greater than equals sign

Have you found that the calculation is "wrong"? The result is only integers, with no fractional part. Look at what this is, and search for "floating point number" (floating). --accurate calculations using floating-point numbers, such as 20.0

Exercise 4: Variables (variable) and naming

Remember = the name is equal to (equal), its function is to name something.
Remember _ is the underscore character (underscore).

Exercise 5: More variables and printing

Search online for all Python formatted characters--



Integer number:%d
unsigned integer number:%u
Octal:%o
Hex:%x%x
Floating point:%f
Science notation:%e%e
Automatic selection of%e or%f according to different values:%g
Automatic selection of%e or%f according to different values:%G

Try using variables to convert inches and pounds into centimeters and kilograms. Do not type the answer directly. Using Python's computational capabilities to complete--
_name = ' Zed A. Shaw '
_age = #not a Lie
_height = #inches
_weight = #lbs
_eyes = ' Blue '
_teeth = ' White '
_hair = ' Brown '

Print "Let's talk about%s."% _name
Print "He ' s%d pounds heavy."%_weight
Print "He ' s%.2f kilogrammes heavy."%0.45359 * _weight
Print "He ' s%d inches tall."%_height
Print "He ' s%.2f centimeters tall."%_height * 2.54

The above program has errors!
Correct:
_name = ' Zed A. Shaw '
_age = #not a Lie
_height = #inches
_weight = #lbs
_eyes = ' Blue '
_teeth = ' White '
_hair = ' Brown '

Print "Let's talk about%s."% _name
Print "He ' s%d pounds heavy."%_weight
Print "He ' s%.2f kilogrammes heavy."% (0.45359 * _weight)
Print "He ' s%d inches tall."%_height
Print "He ' s%.2f centimeters tall."% (_height * 2.54)

Pay attention to the use of parentheses!

Python learns "dumb ways to Learn Python" (supplemented with books)

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.