03 Slide
03 Slide
sqrt(x)
base.
Returns the square root of x. sqrt(4.0) is 2
MathFunctions
sin(x) Returns the sine of x. x represents an angle sin(3.14159 / 2) is 1
Run
in radians. sin(3.14159) is 0
asin(x) Returns the angle in radians for the inverse asin(1.0) is 1.57
of sine. asin(0.5) is 0.523599
cos(x) Returns the cosine of x. x represents an cos(3.14159 / 2) is 0
angle in radians. cos(3.14159) is -1
acos(x) Returns the angle in radians for the inverse acos(1.0) is 0
of cosine. acos(0.5) is 1.0472
tan(x) Returns the tangent of x. x represents an tan(3.14159 / 4) is 1
angle in radians. tan(0.0) is 0
fmod(x, y) Returns the remainder of x/y as double. fmod(2.4, 1.3) is 1.1
degrees(x) Converts angle x from radians to degrees degrees(1.57) is 90
radians(x) Converts angle x from degrees to radians radians(90) is 1.57
ComputeAngles Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
8
Strings and Characters
A string is a sequence of characters. String literals
can be enclosed in matching single quotes (') or
double quotes ("). Python does not have a data type
for characters. A single-character string represents a
character.
DisplayUnicode Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
11
Appendix B: ASCII Character Set
ASCII Character Set is a subset of the Unicode from \u0000 to \u007f
ComputeChange Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
20
Introduction to Objects and Methods
format(item, format-specifier)
10
□□□□□57.47
12345678.92
□□□□□57.40
□□□□□57.00
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
29
Formatting in Scientific Notation
If you change the conversion code from f to e, the
number will be formatted in scientific notation. For
example,
print(format(57.467657, '10.2e'))
print(format(0.0033923, '10.2e'))
print(format(57.4, '10.2e')) 10
print(format(0.53457, '10.2%'))
print(format(0.0033923, '10.2%'))
print(format(7.4, '10.2%'))
10
print(format(57, '10.2%'))
□□□□53.46%
□□□□□0.34%
□□□740.00%
□□5700.00%
print(format(57.467657, '10.2f'))
print(format(57.467657, '<10.2f'))
10
□□□□□57.47
57.47
print(format(59832, '10d'))
print(format(59832, '<10d'))
print(format(59832, '10x')) 10
print(format(59832, '<10x')) □□□□□59832
59832
□□□□□□e9b8
e9b8
20
Welcome to Python
Welcome to Python
□□□Welcome to Python
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
34
Drawing Various Shapes
A turtle contains methods for moving the pen and
setting the pen’s size and speed.
SimpleShapes Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
38
Turtle Drawing with Colors and Fonts
Method Description
ColorShapes Run
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
40