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)