## Python输入输出练习，运算练习，turtle初步练习

1.Hello World！

print('hello world!'

2.简单交互

name=input('输入姓名：')
print('{}好'.format(name))
print('{}好'.format(name[0]))
print('{}好'.format(name[1:]))

3.用户输入两个数字，计算并输出两个数字之和

print(float(input('第1个数：'))+float(input('第2个数：')))

4。用户输入三角形三边长度，并计算三角形的面积：（海伦公式）

a=float(input('第一条边长：'))
b=float(input('第2条边长：'))
c=float(input('第3条边长：'))
p=(a+b+c)/2
s=(p*(p-a)*(p-b)*(p-c))**0.5
print(s)

5.输入半径，计算圆的面积

r=float(input('半径：'))
s=3.14*r*r
print('面积是：',s)

6.画一组同切圆

import turtle
turtle.circle(10)
turtle.circle(20)
turtle.circle(40)
turtle.circle(80)

7.画一个五角星

import turtle
turtle.forward(300)
turtle.left(144)
turtle.forward(300)
turtle.left(144)
turtle.forward(300)
turtle.left(144)
turtle.forward(300)
turtle.left(144)
turtle.forward(300)

8.画一个全黄色的五角星

import turtle
turtle.color('yellow')
turtle.begin_fill()
turtle.fillcolor('yellow')
turtle.forward(300)
turtle.left(144)
turtle.forward(300)
turtle.left(144)
turtle.forward(300)
turtle.left(144)
turtle.forward(300)
turtle.left(144)
turtle.forward(300)
turtle.end_fill()

9.同心圆

import turtle
turtle.penup()
turtle.goto(0,-200)
turtle.pendown()
turtle.circle(200)
turtle.penup()
turtle.goto(0,-150)
turtle.pendown()
turtle.circle(150)
turtle.penup()
turtle.goto(0,-100)
turtle.pendown()
turtle.circle(100)
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.circle(50)

10.国旗

import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.begin_fill()
turtle.fillcolor('yellow')
turtle.penup()
turtle.goto(-310,200)
turtle.pendown()
for i in range(5):
turtle.forward(150)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-150,250)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-100,200)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-110,130)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.penup()
turtle.goto(-160,70)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()

posted on 2017-09-07 11:40  yezless  阅读(202)  评论(0编辑  收藏  举报