Python输入输出练习,运算练习,turtle初步练习
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python输入输出练习,运算练习,turtle初步练习相关的知识,希望对你有一定的参考价值。
1.Hello World!
1
|
print ( ‘Hello World!‘ ) |
简单交互(交互式,文件式)
1 name=input(‘Please in put your name:‘) 2 print(‘hi {}‘.format(name)) 3 print(‘Mr {} hobbit is 吃饭,睡觉,打豆豆‘.format(name[0])) 4 print(‘Dear {} you should go to work!‘.format(name[1]))
3.用户输入两个数字,计算并输出两个数字之和:
print(‘sub is:{}‘.format(float(input(‘第一个数:‘))+float(input(‘第二个数:‘))))
4.用户输入三角形三边长度,并计算三角形的面积:(海伦公式)
1 a=input(‘请输入第一条边:‘) 2 b=input(‘请输入第二条边:‘) 3 c=input("请输入第三条边:") 4 C=(float(a)+float(b)+float(c)) 5 S=(C/2*(float(C/2)-float(a))*(float(C/2)-float(b))*(float(C/2)-float(c)))**0.5 6 print(‘三角形的面积是{}‘.format(S))
5.输入半径,计算圆的面积。
r=input(‘please input r:‘) area=3.1415*float(r)*float(r) print("{:.2f}".format(area))
6.画一组同切圆
1 import turtle 2 turtle.pensize(10) 3 turtle.circle(20) 4 turtle.circle(40) 5 turtle.circle(80) 6 turtle.circle(120)
7.画一个五角星
1 import turtle as t 2 t.speed(1) 3 for i in range(5): 4 t.forward(100) 5 t.right(144)
8.画一个全黄色的五角星
1 import turtle 2 turtle.color(‘yellow‘) 3 turtle.fillcolor(‘yellow‘) 4 turtle.speed(1) 5 turtle.pensize(10) 6 turtle.begin_fill() 7 for i in range(5): 8 turtle.forward(200) 9 turtle.right(144) 10 turtle.end_fill()
附加题1:画一组同心圆:
1 import turtle 2 turtle.penup() 3 turtle.goto(0,-100) 4 turtle.pendown() 5 turtle.circle(100) 6 turtle.penup() 7 turtle.goto(0,-80) 8 turtle.pendown() 9 turtle.circle(80) 10 turtle.penup() 11 turtle.goto(0,-60) 12 turtle.pendown() 13 turtle.circle(60) 14 turtle.penup() 15 turtle.goto(0,-40) 16 turtle.pendown() 17 turtle.circle(40)
画国旗上的五个五角星
import turtle
def draw_square():
turtle.color(‘red‘)
turtle.fillcolor(‘red‘)
# turtle.speed(1)
turtle.penup()
turtle.goto(-200,200)
turtle.pendown()
turtle.begin_fill()
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.forward(200)
turtle.right(90)
turtle.end_fill()
# time.sleep(5)
def draw_big_star():
turtle.color(‘yellow‘)
turtle.fillcolor(‘yellow‘)
# turtle.speed(1)
turtle.penup()
turtle.goto(-175,155)
turtle.pendown()
turtle.begin_fill()
for i in range(5):
turtle.forward(50)
turtle.right(144)
turtle.end_fill()
def draw_smallstar(x,y,z):
turtle.color(‘yellow‘)
turtle.fillcolor(‘yellow‘)
# turtle.speed(1)
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
turtle.begin_fill()
turtle.right(z)
for i in range(5):
turtle.forward(15)
turtle.right(144)
turtle.end_fill()
draw_square()
draw_big_star()
draw_smallstar(-110,175,5)
draw_smallstar(-90,155,15)
draw_smallstar(-95,125,25)
draw_smallstar(-110,105,0)
以上是关于Python输入输出练习,运算练习,turtle初步练习的主要内容,如果未能解决你的问题,请参考以下文章