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 ...
随机推荐
- Thread(线程)四
今天继续讲讲线程的异常处理.线程取消.多线程的临时变量和线程安全lock的问题. 1.异步处理. 一般来说如果是同步方法的异步处理,我们大多都是try catch住,但是异步方法应该怎么做呢. #re ...
- unable to create …
问题描述: 在新建Android Application时会出现unable to create the selected property page 解决方法: 将用户PATH路径中的jdk路径放到 ...
- NYOJ--187--快速查找素数(筛选法,素数打表)
快速查找素数 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 现在给你一个正整数N,要你快速的找出在2.....N这些数里面所有的素数. 输入 给出一个正整数数N ...
- 转换Json中的时间戳为标准时间格式
//出自http://www.cnblogs.com/ahjesus function ConvertJSONDateToJSDate(jsonDate) { /// <su ...
- equals()与 == 比较,hashCode方法
1.Object类 Object类是java中一切类的父类,java中所有的类都直接或间接 继承自Object类 Object中定义的方法不多,原因在于,java的类多种多样 ...
- CentOS 6.5安装JDK、Tomcat、Mysql
安装JDK 1.下载JDK7 下载jdk-7u79-linux-x64.tar.gz 百度网盘下载地址:https://pan.baidu.com/s/1c1JZo2k 在Linux上新建/usr/j ...
- Python pyspider 安装与开发
PySpider 简介 PySpider是一个国人编写的强大的网络爬虫系统并带有强大的WebUI.采用Python语言编写,分布式架构,支持多种数据库后端,强大的WebUI支持脚本编辑器.任务监视器, ...
- JavaScript高级程序设计 - 阅读笔记
[本博客为原创:http://www.cnblogs.com/HeavenBin/] 前言: 大致花费了一个星期的时间把这本书认真看了半本,下面是我做的阅读笔记,希望能够让看这本书的人有个大致的参考. ...
- HTML-JS基础 变量与输入输出 运算符 分支结构
js中的变量 1.JS中变量声明的写法: var num=10;//使用var声明的变量属于局部变量只在当前作用域内有效 num=10;//不用var声明的变量,默认为全局变量,在整个JS文件中都有效 ...
- Run Unit API Testing Which Was Distributed To Multiple Test Agents
Recently I am blocked by a very weird issue, from the VS installed machine, I can run performance te ...