简单的Python小程序
来自CloudWiki
排错
例题
斐波那契数列的计算
a,b = 0,1 while a<1000: print(a,end=',') a,b = b,a+b
4)圆面积的计算:
r=25 area=3.1415*r*r print(area) print("{:.2f}".format(area))#只输出两位小数
5)绘制五角红星
from turtle import * color('red','red') begin_fill() for i in range(5): fd(200) rt(144) end_fill() done()
绘制七彩圆圈:
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()
- Python小程序之圆面积的计算
- 根据圆的半径求出圆的面积
radius = 25 # 圆的半径是25 area = 3.1415 * radius * radius # 输入计算圆面积的公式 print(area) print("{:.2f}".format(area)) # 只输出两位小数
- Python小程序之人名对话
- 获得字符串的全部或部分字符
name = input("输入姓名:") print("%s 同学,学好Python,前途无量!"%name) print("%s 大侠,学好Python,大展拳脚!"%name[0]) print("%s 哥哥,学好Python,人见人爱!"%name[1:])
- Python小程序之同切圆的绘制:
import turtle # 引用turtle 库 turtle.pensize(2) # 设置画笔宽度为2 像素 turtle.circle(10) # 绘制半径为10 像素的圆 turtle.circle(40) # 绘制半径为40 像素的圆 turtle.circle(80) # 绘制半径为80 像素的圆 turtle.circle(160) # 绘制半径为160 像素的圆