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

Python练习

时间:2017-09-08 18:09:03      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:输出   goto   begin   images   ima   span   技术分享   img   第一个   

1.输出hello world

print(‘hello world‘)

2.简单交互

name=input(‘name=:‘)
print(‘我的名字是:{}‘.format(name))

3.计算两数之和

print(‘两者之和为:%.0f‘%float(float(input(‘输入第一个数字:‘))+float(input(‘输入第二个数字:‘))))

4.计算三角形面积

a=float(input(‘a=‘))
b=float(input(‘b=‘))
c=float(input(‘c=‘))
p=float((float(a+b+c))/2)
print(‘三角形abc的面积为:%.0f‘%float((p*(p-a)*(p-b)*(p-c))**0.5))

5.计算圆的面积

r=float(input(‘半径为:‘))
print(‘半径为{}的面积为:%.2f‘.format(r) %float(3.1314 * r * r))

6.画同切圆

import turtle
turtle.circle(5)
turtle.circle(10)
turtle.circle(15)
turtle.circle(20)

7.画五角星

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

8.画一个填充颜色的五角星

import turtle
turtle.bgcolor(‘red‘)
turtle.color(‘yellow‘)
turtle.fillcolor(‘yellow‘)

turtle.begin_fill()

turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)

turtle.end_fill()

9.国旗

import turtle
turtle.color(‘yellow‘)
turtle.bgcolor(‘red‘)
turtle.fillcolor(‘yellow‘)



turtle.begin_fill()

turtle.up()
turtle.goto(-200,100)
turtle.down()

turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.right(144)
turtle.forward(150)
turtle.end_fill()


turtle.begin_fill()

turtle.up()
turtle.goto(-80,160)
turtle.down()


turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()


turtle.begin_fill()

turtle.up()
turtle.goto(-22,68)
turtle.down()


turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()

turtle.begin_fill()

turtle.up()
turtle.goto(-30,110)
turtle.down()


turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()


turtle.begin_fill()

turtle.up()
turtle.goto(-45,-10)
turtle.down()


turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.right(144)
turtle.forward(50)
turtle.end_fill()

国旗效果图

技术分享

 

Python练习

标签:输出   goto   begin   images   ima   span   技术分享   img   第一个   

原文地址:http://www.cnblogs.com/xujiekai/p/7495039.html

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