>>> :python交互式语言环境提示符 ,输入exit() 或 quit() 可以退出
IPO程序编写方法: input , output , process
练习:
1.1 斐波那契数列的计算
#CalFibonacci.py
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()
fd():即forward(),表示向前多少个单位, t.bk或t.back()是向后退
lt(),rt():left right,是向左右转过多少度
penup pendown :提笔或落笔,penup时不作画,即turtle的移动不留下笔迹,pendown时作画
1.4 程序运行计时
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))