Hello World!

print('hello world!')

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

name = input("输入姓名:")
print("{}同学,学好Python,前途无量!".format(name))

用户输入两个数字,计算并输出两个数字之和:

a = float(input('输入第一个数字:'))
b = float(input('输入第二个数字:'))
s = a+b
print(s)

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

x = float(input('输入第一条边:'))
y = float(input('输入第二条边:'))
z = float(input('输入第三条边:'))
p = float((x+y+z)*0.5)
s = float((p*(p-x)*(p-y)*(p-z))**0.5)
print('面积是;{0}'.format(s))

输入半径,计算圆的面积。

r = 25
area = 3.1415 * r * r
print(area)
print("{:.2f}".format(area))

画一组同切圆

import turtle
turtle.pensize(2)
turtle.circle(10)
turtle.circle(40)
turtle.circle(80)
turtle.circle(160)

画一个五角星

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)

 

画一个全黄色的五角星

import turtle
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 on 2017-09-06 11:43  18-刘卓辉  阅读(234)  评论(0编辑  收藏  举报