python小练习、小例题1

这是全国二级等级考试书里的,如果你是萌新看不懂,可以在评论区下面留言,我可以在出个解释代码的,如果没有人需要,我就不出了。

#calculate_circle_area.py
r = 25
area=3.1415*r*r
print(area)
print("{:.2f}".format(area))

#calculate_fibonacci_sequence.py
a,b=0,1
while a<1000:
    print(a,end=",")
    a,b=b,a+b
    
#calculate_run_time.py
import time
limit = 10*1000*1000
start = time.perf_counter()
while True:
    limit -= 1
    if limit <= 0:
        break
delta = time.perf_counter() - start
print("程序运行的时间是:{}秒".format(delta))

#darw_seven_colorful_circles.py
import turtle
colors = ['red','orange','yellow','green','blue','indigo','purple']
for i in range(7):
    c = colors[i]
    turtle.color(c,c)
    turtle.begin_fill()
    turtle.rt(360/7)
    turtle.circle(50)
    turtle.end_fill()
turtle.done()
    
#draw_star.py
from turtle import *
color('red','red')
begin_fill()
for i in range(5):
    fd(150)
    rt(144)
end_fill()
done()

这是我根据注释后面的意思写出来的代码

#calculate_circle_area.py
#CalculateCircleArea.py
r = int(input("input radius,please: "))
pai = 3.1415926
area = r * r * pai
print('{:.2f}'.format(area))

#CalculateFibonacciSequence.py
a,b=0,1
while a<1000:
    print(a,end=" ")
    a,b=b,a+b

#CalculateRunTime.py
import time
start = time.perf_counter()
function_time=time.perf_counter()-start
print("{:.8f}秒".format(function_time))

#DrawSevenColorfulCircles.py
import turtle as t
t.speed(0)
t.setup(666,666)
t.bgcolor('black')
t.pensize(5)
colors = ['white','seashell','yellow','cyan','orange','green','tomato']
for i in range(7):
    c = colors[i]
    t.color(c,c)
    t.begin_fill()
    t.circle(50)
    t.right(46)
    t.end_fill()

#DrawStar.py
import turtle as t
t.setup(666,666)
t.bgcolor('brown')
t.pencolor('yellow')
t.pensize(5)
t.fillcolor('yellow')
t.begin_fill()
for i in range(5):
    t.forward(150)
    t.right(144)
t.end_fill()

你可能感兴趣的:(Python例题库,python)