博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python输入输出练习,运算练习,turtle初步练习
阅读量:7069 次
发布时间:2019-06-28

本文共 2626 字,大约阅读时间需要 8 分钟。

1、Hello World!

print('网络工程2班14')

 

2、简单交互(交互式,文件式)

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

print('两数只和为:%.2f'%(float(input('请输入第一个数:'))+float(input('请输入第二个数:'))))

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

a=float(input('请输入第一条边边长:'))b=float(input('请输入第二条边边长:'))c=float(input('请输入第三条边边长:'))s=(a+b+c)/2area=(s*(s-a)*(s-b)*(s-c))**0.5print('三角形的面积是%0.2f'%area)

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

r=input('输入圆的半径:')area=3.1415*float(r)*float(r)print('这个圆的面积为:{}'.format(area))print('这个圆的面积为(保留2位小数){:.2f}'.format(area))

6、画一组同切圆

 

import turtleturtle.circle(15)turtle.circle(30)turtle.circle(45)

 

7、画一个五角星

import turtlefor i in range(5):    turtle.forward(100)    turtle.left(144)

 

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

import turtleturtle.shape('turtle')turtle.color('red')turtle.fillcolor('red')turtle.penup()turtle.goto(0,-100)turtle.pendown()turtle.begin_fill()turtle.circle(100)turtle.penup()turtle.end_fill()turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.penup()turtle.goto(-48,9)turtle.pendown()for i in range(5):    turtle.forward(100)    turtle.right(144)turtle.end_fill()

 

 

思考:

1、画一组同心圆

import turtleturtle.penup()turtle.goto(0,-200)turtle.pendown()turtle.circle(200)turtle.penup()turtle.goto(0,-100)turtle.pendown()turtle.circle(100)

2、画国旗上的五个五角星。

import turtleturtle.speed(41)turtle.penup()turtle.goto(-300,240)turtle.pendown()##画国旗背景turtle.fillcolor('red')turtle.begin_fill()turtle.forward(600)turtle.right(90)turtle.forward(400)turtle.right(90)turtle.forward(600)turtle.right(90)turtle.forward(400)turtle.end_fill()##画大五角星turtle.penup()turtle.goto(-263,163)turtle.pendown()turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.right(90)for i in range(5):    turtle.forward(100)    turtle.right(144)turtle.end_fill()##画小五角星##第一个turtle.penup()turtle.goto(-126,211)turtle.pendown()turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.right(90)for i in range(5):    turtle.forward(20)    turtle.right(144)turtle.end_fill()##第二个turtle.penup()turtle.goto(-90,140)turtle.pendown()turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.right(90)for i in range(5):    turtle.forward(20)    turtle.right(144)turtle.end_fill()##第三个turtle.penup()turtle.goto(-126,64)turtle.pendown()turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.right(90)for i in range(5):    turtle.forward(20)    turtle.right(144)turtle.end_fill()##第四个turtle.penup()turtle.goto(-192,30)turtle.pendown()turtle.color('yellow')turtle.fillcolor('yellow')turtle.begin_fill()turtle.right(90)for i in range(5):    turtle.forward(20)    turtle.right(144)turtle.end_fill()

 

转载于:https://www.cnblogs.com/gzw2017/p/7489285.html

你可能感兴趣的文章
JavaScript继承方式详解
查看>>
解决win7旗舰版无法打开微软论坛
查看>>
烂泥:高负载均衡学习haproxy之安装与配置
查看>>
路由方式通过Iptables解决内网绑定的公网IP问题
查看>>
Ubuntu配置DNS
查看>>
我的友情链接
查看>>
我的碎碎念
查看>>
pymysql添加更新数据没效果
查看>>
TuShare -财经数据接口包
查看>>
数据之加密与解密
查看>>
冷门java程序员的理念
查看>>
JavaScript实现X秒后自动跳转
查看>>
extjs formPanel里的元素居中显示
查看>>
PHP系列(十)GD库
查看>>
android笔记3-文件读取
查看>>
扫描仪和数码相机TWAIN控件VintaSoftTwain.NET Library下载
查看>>
友元关系与继承
查看>>
关于ffmpeg的error返回值
查看>>
CentOS装完后没有网卡配置文件ifcfg-eth0的解决方法
查看>>
JAVA排序的面试题
查看>>