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 ...
随机推荐
- HttpStatus各种状态
JS.ns("JS.HTTPStatus","JS.XMLHttpRequest"); /** * FC 2616 HTTP1.1规范的HTTP Status状 ...
- C# 将数据表导出到Excel通用方法
DataGrid dg = new DataGrid(); dg.DataSource = dt; dg.DataBind(); Response.Clear(); Response.Buffer = ...
- ABP+AdminLTE+Bootstrap Table权限管理系统第五节--WBEAPI及SwaggerUI
一,Web API ABP的动态WebApi实现了直接对服务层的调用(其实病没有跨过ApiController,只是将ApiController公共化,对于这一点的处理类似于MVC,对服务端的 调用没 ...
- POJ--1088--dp--滑雪
#include<iostream> using namespace std; ; }; }; int dp(int,int); int row,col; int main() { whi ...
- java变量、二进制、数据类型、原码、补码、反码
1. 变量 1. 他 她 我 你 某人 佚名 旺财 X-man x = 1 您好! 它 (变量就是自然语言中的代词) 2. int age = 15;// 00000000 0000 ...
- shell 脚本编程之特殊变量
$0 当前脚本的文件名$n 传递给脚本或函数的参数.n 是一个数字,表示第几个参数.例如,第一个参数是$1,第二个参数是$2.$# 传递给脚本或函数的参数个数.$* 传递给脚本或函数的所有参数.$@ ...
- ionic3 app 退出应用程序
在ionic3 打包的app,如果要实现代码来控制应用程序的推出. 在android以下代码是可以的,但是在ios是不支持的.因为这不适用于ios app,因为苹果apple 不允许应用程序以编程的方 ...
- 模拟exit()退出命令实现
1.当输入exit命令是退出程序,如果输入其他的就打印====> 方法一while True: username=input("请输入你的用户名:>>>") ...
- Java静态绑定与动态绑定
程序绑定的概念: 绑定指的是一个方法的调用与方法所在的类(方法主体)关联起来.对java来说,绑定分为静态绑定和动态绑定:或者叫做前期绑定和后期绑定. 静态绑定: 在程序执行前方法已经被绑定(也就是说 ...
- scope引起的问题
背景 执行mvn clean test命令提示部分包不存在,但通过eclipse的clean操作后可以执行mvn test命令 解决方法 mvn clean操作为清空编译的class文件,test的话 ...