Python study notes 1.2

Example 1: Calculation of the area of ​​a circle Calculate the area of ​​a circle
based on the radius r
Interactive
>>> r = 25
>>> area = 3.1415 * r * r
>>> print(area)
1963.4375000000002
>>> print(" {:.2f} F".format(area))
1963.44

Calculate the circle area according to the radius r and the
output result is as follows:
1963.4375000000002
1963.44
Save as CalCircle.py file and run the
file format

Example 2: Drawing with tangent circles
Draw multiple tangent circles

import turtle
turtle.pensize(2)
turtle.circle(10)
turtle.circle(40)
turtle.circle(80)
turtle.circle(160)


Save as TangentCirclesDraw.py file and run the file format

Example 3: Pentagram drawingDraw
a pentagram

from turtle import *
color('red', 'red')
begin_fill()
for i in range(5):
fd(200)
rt(144)
end_fill()
done()


Save as StarDraw.py file and run the
file format

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324692355&siteId=291194637