#Python#输入输出练习,运算练习,turtle初步练习
- Hello World!
- 简单交互(交互式,文件式)教材P19
-
radius=25 area=3.1415*radius*radius print(area) print('{:.2f}'.format(area))
- 用户输入两个数字,计算并输出两个数字之和:
-
a=input('请输入第一个数字:') b=input("请输入第二个数字:") c=float(a)+float(b) print('两数之和为:') print(c)
- 用户输入三角形三边长度,并计算三角形的面积:(海伦公式)
-
while 1==1: a=float (input('请输入三角形的第一条边:\n')) b=float (input('请输入三角形的第二条边:\n')) c=float (input('请输入三角形的第三条边:\n')) if (a+b>c)and (a+c>b)and (b+c>a)and abs((a-b)<c)and abs((a-c)<b)and abs((b-c)<a): break else: print('输入有误,请重新输入!\n') p=float ((a+b+c)/2 ) s=float(p*(p-a)*(p-b)*(p-c))**0.5 print ('面积为%.2f'%s)
- 输入半径,计算圆的面积。
-
#r=float(input('请输入圆的半径:')) print('面积为:',3.1415*float(input('请输入圆的半径:'))**2)
- 画一组同切圆
-
import turtle turtle.circle(10) turtle.circle(40) turtle.circle(80) turtle.circle(100)
- 画一个五角星
-
import turtle for i in range(5): turtle.forward(100) turtle.left(144)
- 画一个全黄色的五角星
-
import turtle turtle.shape('turtle') turtle.speed(10) turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.left(144) turtle.end_fill()
- 思考
- 画一组同心圆。
-
import turtle turtle.speed(10) turtle.penup() turtle.goto(0,100) turtle.pendown() turtle.circle(10) turtle.penup() turtle.goto(0,80) turtle.pendown() turtle.circle(30) turtle.penup() turtle.goto(0,60) turtle.pendown() turtle.circle(50) turtle.penup() turtle.goto(0,40) turtle.pendown() turtle.circle(70)
- 画国旗上的五个五角星。
import turtle turtle.speed(41) turtle.penup() turtle.goto(-300,240) turtle.pendown() ##画国旗背景 turtle.fillcolor('red') turtle.begin_fill() turtle.forward(600) turtle.right(90) turtle.forward(400) turtle.right(90) turtle.forward(600) turtle.right(90) turtle.forward(400) turtle.end_fill() ##画大五角星 turtle.penup() turtle.goto(-263,163) turtle.pendown() turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() turtle.right(90) for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill() ##画小五角星 ##第一个 turtle.penup() turtle.goto(-126,211) turtle.pendown() turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() turtle.right(90) for i in range(5): turtle.forward(20) turtle.right(144) turtle.end_fill() ##第二个 turtle.penup() turtle.goto(-100,160) turtle.pendown() turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() turtle.right(90) for i in range(5): turtle.forward(20) turtle.right(144) turtle.end_fill() ##第三个 turtle.penup() turtle.goto(-107,116) turtle.pendown() turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() turtle.right(90) for i in range(5): turtle.forward(20) turtle.right(144) turtle.end_fill() ##第四个 turtle.penup() turtle.goto(-133,95) turtle.pendown() turtle.color('yellow') turtle.fillcolor('yellow') turtle.begin_fill() turtle.right(90) for i in range(5): turtle.forward(20) turtle.right(144) turtle.end_fill()