学习计算机二级python第一天
python
- 程序运行
- 编程方法
- 输入(Input)
- 处理(Process)
- 输出(Output)
- 语言特点
实例
1.1 斐波那契数列计算
a,b=0,1
while a <1000:
print(a,end=',')
a,b=b,a+b
1.2 圆面积计算
r=25
area=3.1415*r*r
print(area)
print("{:.2f}".format(area))
1.3 绘制五角星
from turtle import *
color('red','red')
begin_fill()
for i in range(5):
fd(200)
rt(144)
end_fill()
done()
1.4 程序运行计时
import time
limit=100*1000*10000
start=time.perf_counter()
while True:
limit-=1
if limit<=0:
break
delta=time.perf_counter ()-start
print("程序运行时间是:{}秒;".format(delta))
1.5 绘制七彩圆圈
import turtle
import turtle
color=["red","orange","yellow","green","blue","indigo","purple"]
for i in range(7):
c=color[i]
turtle.color(c,c)
turtle.begin_fill()
turtle.rt(360/7)
turtle.circle(50)
turtle.end_fill()
turtle.done()