Python练习

1.Hello World!

print('Hello World!')

2.简单交互(交互式,文件式)教材P19

name = input("输入名字:")
print("{}同学,学好python,前途无量!".format(name))
print("{}大侠,学好python,前途无量!".format(name[0]))
print("{}哥哥,学好python,前途无量!".format(name[1:]))

3、用户输入两个数字,计算并输出两个数字之和(尝试用一行代码实现)

print("结果为:%.2f"%(float(input('输入第一个变量:'))+float(input('输入第二个变量:'))))

4、用户输入三角形三边长度,并计算三角形的面积:(海伦公式)

a=float(input("请输入三角形的第一条边:"))
b=float(input("请输入三角形的第二条边:"))
c=float(input("请输入三角形的第三条边:"))
p=float((a+b+c)/2)
area=float((p*(p-a)*(p-b)*(p-c))**0.5)
print("面积为:%.2f"%area)

5、输入半径,计算圆的面积

radius = float(input("输入圆的半径:"))
area = float(3.1415 * radius * radius)
print("面积为;%.2f"%area)

6、画一组同切圆

import turtle
turtle.circle(10)
turtle.circle(20)
turtle.circle(30)
turtle.circle(40)
turtle.circle(50)
turtle.circle(60)

7、画一个五角星

import turtle
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)

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

import turtle
turtle.bgcolor("red")
turtle.color("yellow")
turtle.fillcolor("yellow")
turtle.begin_fill()
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.right(144)
turtle.forward(200)
turtle.end_fill()

  

 

posted @ 2017-09-08 13:45  34-潘志文  阅读(110)  评论(0编辑  收藏  举报