一.问候
print('hello world')
二.简单交互
name = input ('your name:')print('%s hello' %name)print('%s hello' %name
三.输入两个数字,并计算和
a1 = input('第一个数字:')a2 = input('第二个数字:')sum = float(a1)+float(a2)print(folat(sum))
四.一句话求和
print('两数之和%.1f' %(float(input('输入第一个数:'))+float(input('输入第二个数:'))))
五. 输入三角形边长,并计算面积
radius = float(input("输入R:"))area = float(3.1415 * radius * radius)print("面积:%.2f"%area)
六.画圆
import turtleturtle.pensize(1)turtle.cricle(10)turtle.cricle(20)
七.画五角星
import turtleturtle.bgcolor("red")turtle.color("yellow")turtle.fillcolor("yellow")turtle.begin_fill()turtle.forword(100)turtle.left(144)turtle.forword(100)turtle.left(144)turtle.forword(100)turtle.left(144)turtle.forword(100)turtle.left(144)turtle.forword(100)turtle.end_fill()
八.给五角星填充颜色
import turtleturtle.bgcolor('red')turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.forward(100)turtle.right(144)turtle.forward(100)turtle.right(144)turtle.forward(100)turtle.right(144)turtle.forward(100)turtle.right(144)turtle.forward(100)turtle.end_fill()
9国旗
import turtleturtle.color('yellow')turtle.bgcolor('red')turtle.fillcolor('yellow')turtle.begin_fill()turtle.up()turtle.goto(-200,100)turtle.down()turtle.forward(150)turtle.right(144)turtle.forward(150)turtle.right(144)turtle.forward(150)turtle.right(144)turtle.forward(150)turtle.right(144)turtle.forward(150)turtle.end_fill()turtle.begin_fill()turtle.up()turtle.goto(-80,160)turtle.down()turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.end_fill()turtle.begin_fill()turtle.up()turtle.goto(-22,68)turtle.down()turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.end_fill()turtle.begin_fill()turtle.up()turtle.goto(-30,110)turtle.down()turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.end_fill()turtle.begin_fill()turtle.up()turtle.goto(-45,-10)turtle.down()turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.right(144)turtle.forward(50)turtle.end_fill()