码迷,mamicode.com
首页 > 编程语言 > 详细

python小练习

时间:2017-09-08 23:54:20      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:pre   world   yellow   数字   第一条   长度   第一个   计算   format   

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(180)
turtle.right(120)
turtle.forward(180)
turtle.right(120)
turtle.forward(180)
turtle.right(120)
turtle.forward(180)
turtle.right(120)
turtle.forward(180)

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()

  

python小练习

标签:pre   world   yellow   数字   第一条   长度   第一个   计算   format   

原文地址:http://www.cnblogs.com/elewen/p/7496769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!