0
点赞
收藏
分享

微信扫一扫

Python小程序

蒸熟的土豆 2022-01-15 阅读 92

目录

一、斐波那契数列的计算

二、根据圆的半径计算圆的面积

三、用Python绘制五角红星图形

四、程序运行计时

五、绘制七彩圆圈


一、斐波那契数列的计算

F(0)=0,F(1)=1,F(n)=F(n-2)+F(n-1),其中n>=2

a,b=0,1
while a<1000:    #输出不大于1000的序列
    print(a,end=',')
    a,b=b,a+b

二、根据圆的半径计算圆的面积

r=25   #圆的半径是25
area=3.1415*r**2
print(area)
print("{:.2f}".format(area))   #运算结果保留两位小数

三、用Python绘制五角红星图形

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

四、程序运行计时

对一个循环计数一千万次的程序记录并输出其运行时间

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))

五、绘制七彩圆圈

绘制7个不同颜色的圆圈,组成七彩圆圈

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()

举报

相关推荐

0 条评论