1、Hello World!
print('网络工程2班14')
2、简单交互(交互式,文件式)
3、用户输入两个数字,计算并输出两个数字之和(尝试用一行代码实现)。
print('两数只和为:%.2f'%(float(input('请输入第一个数:'))+float(input('请输入第二个数:'))))
4、用户输入三角形三边长度,并计算三角形的面积:(海伦公式)
a=float(input('请输入第一条边边长:'))b=float(input('请输入第二条边边长:'))c=float(input('请输入第三条边边长:'))s=(a+b+c)/2area=(s*(s-a)*(s-b)*(s-c))**0.5print('三角形的面积是%0.2f'%area)
5、输入半径,计算圆的面积。
r=input('输入圆的半径:')area=3.1415*float(r)*float(r)print('这个圆的面积为:{}'.format(area))print('这个圆的面积为(保留2位小数){:.2f}'.format(area))
6、画一组同切圆
import turtleturtle.circle(15)turtle.circle(30)turtle.circle(45)
7、画一个五角星
import turtlefor i in range(5): turtle.forward(100) turtle.left(144)
8、画一个全黄色的五角星
import turtleturtle.shape('turtle')turtle.color('red')turtle.fillcolor('red')turtle.penup()turtle.goto(0,-100)turtle.pendown()turtle.begin_fill()turtle.circle(100)turtle.penup()turtle.end_fill()turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.penup()turtle.goto(-48,9)turtle.pendown()for i in range(5): turtle.forward(100) turtle.right(144)turtle.end_fill()
思考:
1、画一组同心圆
import turtleturtle.penup()turtle.goto(0,-200)turtle.pendown()turtle.circle(200)turtle.penup()turtle.goto(0,-100)turtle.pendown()turtle.circle(100)
2、画国旗上的五个五角星。
import turtleturtle.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(-90,140)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(-126,64)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(-192,30)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()