Python输入输出练习,运算练习,turtle初步练习
- Hello World!
- 简单交互(交互式,文件式)教材P19
radius=25
area=3.1415*radius*radius
print(area)
print('{:.2f}'.format(area))- 用户输入两个数字,计算并输出两个数字之和:
a=input('请输入第一个数字:')
b=input("请输入第二个数字:")
c=float(a)+float(b)
print('两数之和为:')
print(c)- 用户输入三角形三边长度,并计算三角形的面积:(海伦公式)
while 1==1:
a=float (input('请输入三角形的第一条边:\n'))
b=float (input('请输入三角形的第二条边:\n'))
c=float (input('请输入三角形的第三条边:\n'))
if (a+b>c)and (a+c>b)and (b+c>a)and abs((a-b)<c)and abs((a-c)<b)and abs((b-c)<a):
break else:
print('输入有误,请重新输入!\n')
p=float ((a+b+c)/2 )
s=float(p*(p-a)*(p-b)*(p-c))**0.5
print ('面积为%.2f'%s)
- 输入半径,计算圆的面积。
#r=float(input('请输入圆的半径:'))
print('面积为:',3.1415*float(input('请输入圆的半径:'))**2)- 画一组同切圆
import turtle
turtle.circle(10)
turtle.circle(40)
turtle.circle(80)
turtle.circle(100)- 画一个五角星
import turtle
for i in range(5):
turtle.forward(100)
turtle.left(144)- 画一个全黄色的五角星
import turtle
turtle.shape('turtle')
turtle.speed(10)
turtle.color('yellow')
turtle.fillcolor('yellow')
turtle.begin_fill()
for i in range(5):
turtle.forward(100)
turtle.left(144) turtle.end_fill()- 思考
- 画一组同心圆。
import turtle
turtle.speed(10)
turtle.penup()
turtle.goto(0,100)
turtle.pendown()
turtle.circle(10) turtle.penup()
turtle.goto(0,80)
turtle.pendown()
turtle.circle(30) turtle.penup()
turtle.goto(0,60)
turtle.pendown()
turtle.circle(50) turtle.penup()
turtle.goto(0,40)
turtle.pendown()
turtle.circle(70)- 画国旗上的五个五角星。
import turtle
turtle.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(-100,160)
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(-107,116)
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(-133,95)
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()
Python输入输出练习,运算练习,turtle初步练习的更多相关文章
- Python 输入输出 数据类型 变量
python输入输出 数据类型 变量 输入输出 print()在Python3中是函数 >>>print('hello world') #print注意print前面不要有任何空格 ...
- python的三元运算
python的三元运算是先输出结果,再判定条件.其格式如下: >>> def f(x,y): return x - y if x>y else abs(x-y) #如果x大于y ...
- python字符串的运算有哪些
python字符串的运算有哪些 1,链接符号 + 2,判断字符串是否在某个字符串中 ‘s’ in ‘this’ 返回bool 3,字符串索引 a="this a my" a[0], ...
- #6 Python数据类型及运算
前言 前文讲述了Python的输入输出以及变量的相关知识点,本节将探讨Python的数据类型以及数据之间的运算方式! 一.Python数据类型 上一节弄清了变量,其实变量所指向的值是有自己独特的数据类 ...
- python基础(四)运算
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python的运算符和其他语言类似 (我们暂时只了解这些运算符的基本用法,方便我们 ...
- Python学习教程(learning Python)--3.3.2 Python的关系运算
如果if的condition不用布尔表达式来做条件判断而采用关系表达式,实际上关系表达式运算的结果要么是True要么是False.下面我们先了解一些有关关系运算符的基础知识,如下表所示. 做个小程序测 ...
- Python输入输出(IO)
程序会有输入和输出,输入可以从标准输入或是从一个文件读入数据,程序的输出可以以一种友好可读的方式(human-readable)打印出来,或是写进一个文件,而标准输入和标准输出(键盘和显示器)在程序的 ...
- Python学习入门基础教程(learning Python)--3.3.2 Python的关系运算
如果if的condition不用布尔表达式来做条件判断而采用关系表达式,实际上关系表达式运算的结果要么是True要么是False.下面我们先了解一些有关关系运算符的基础知识,如下表所示. 做个小程序测 ...
- 吾八哥学Python(五):Python基本数学运算
今天我们学习Python里的基本数学运算方法,还是通过例子来练习吧! 加减乘除求余 #加法 print(12+34) #减法 print(30-10.0) #乘法 print(3*5) #除法 pri ...
随机推荐
- 小兴趣:修改Hosts文件,禁止访问指定网页
不知道Hosts文件什么鬼的朋友可以在网上搜索一下(大牛勿喷- -) 访问网址时,先查询本地的Hosts文件,那么如果我们将Hosts文件中的网址与IP的映射修改之后,将访问错误的IP. 如在文件尾追 ...
- TASKCTL产品功能清单-转载
功能分类 功能描述 一级 二级 关系 调度控制 作业依赖关系调度 作业依赖关系调度是调度最基本的功能,指作业间具有顺序的运行,比如:a.b.c三个作业,只有当a完成后才运行b,b完成才能运行c 作业并 ...
- 点击文字选中radio
<html><body><form action="" name="form1" method="post"& ...
- xxe漏洞的学习与利用总结
前言 对于xxe漏洞的认识一直都不是很清楚,而在我为期不长的挖洞生涯中也没有遇到过,所以就想着总结一下,撰写此文以作为记录,加深自己对xxe漏洞的认识. xml基础知识 要了解xxe漏洞,那么一定得先 ...
- iOS蓝牙BLE开发
蓝牙是一个标准的无线通讯协议,具有设备成本低.传输距离近和功耗低等特点,被广泛的应用在多种场合.蓝牙一般分为传统蓝牙和BLE两种模式:传统蓝牙可以传输音频等较大数据量,距离近.功耗相对大:而BLE则用 ...
- Opentk教程系列-1绘制一个三角形
本系列教程翻译自Neo Kabuto's Blog.已经取得作者授权. 本文原文地址http://neokabuto.blogspot.com/2013/02/opentk-tutorial-1-op ...
- 命令行创建Maven项目卡住以及出错解决办法。
第一次通过命令行创建maven项目.结果,果不其然啊,还是出问题了,不过出问题比没有出问题强,知道哪里有问题并学会解决也是一种收获. 遇到的第一个问题,在从仓库下载东西的时候会卡住,我开始以为是网速问 ...
- 利用css实现页面加载时旋转动画
有时浏览一些网站时在刚加载页面时候会出现一个滚动动画如下图,特别是对于一些移动端的站点或者混合应用来说应该用户体验会好很多,扒了下页面发现是用css样式控制的,于是把页面以及css样式赋值了下来, h ...
- STL简单的介绍
我们要知道C++的含义:C语言 + 类 + 模板 (STL就是典型的代表) STL是Standard Template Library的简称,中文名是标准模库.从根本上说,STL是一些“容器”的集合 ...
- 当使用composer安装组件时提示错误
这种情况可以重装一下fxp/composer-asset-plugin 具体命令: php composer.phar global require "fxp/composer-asset- ...