离python二级考还有十几天,吓的我赶紧买了本python教程

本文通过五个生动的Python编程实例,包括斐波那契数列生成、圆面积计算、五角星绘制、程序运行时间测量及七彩圆圈的创建,展示了Python在不同场景下的应用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不多说,前面粗略的看一下,直接进入实例部分,敲代码实践才是硬道理

实例1 斐波那契数列 

#feibonaqieshulie #这英文我是真的不会,不过拼音也勉强够用
a,b = 0,1
while a<1000:
print(a,end=",")
a,b = b,a+b

实例2 简单圆面积的计算

#Area yuan
r = 20
Area = 3.14
15*(r*r)
print("{:.2f}".format(Area))

实例3 绘制五角星(有点小炫酷)

#DrawStar.py
from turtle import *            #turtle为python制图的一种函数
color('red','red')    #color里面前面类似画五角星的笔,后面则是框架画好之后一桶颜料倒上去
begin_fill()
for i in range(5):
fd(200)
rt(144)
end_fill()
done()

实例4 一个程序运行的时间

#calRunTime.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))

实例5 七彩圆圈

#DrawSevenColorfulCorcles.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()

转载于:https://www.cnblogs.com/dmsbknxd/p/10519158.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值