• 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初步练习的更多相关文章

  1. Python 输入输出 数据类型 变量

    python输入输出 数据类型 变量 输入输出 print()在Python3中是函数 >>>print('hello world') #print注意print前面不要有任何空格 ...

  2. python的三元运算

    python的三元运算是先输出结果,再判定条件.其格式如下: >>> def f(x,y): return x - y if x>y else abs(x-y) #如果x大于y ...

  3. python字符串的运算有哪些

    python字符串的运算有哪些 1,链接符号 + 2,判断字符串是否在某个字符串中 ‘s’ in ‘this’ 返回bool 3,字符串索引 a="this a my" a[0], ...

  4. #6 Python数据类型及运算

    前言 前文讲述了Python的输入输出以及变量的相关知识点,本节将探讨Python的数据类型以及数据之间的运算方式! 一.Python数据类型 上一节弄清了变量,其实变量所指向的值是有自己独特的数据类 ...

  5. python基础(四)运算

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python的运算符和其他语言类似 (我们暂时只了解这些运算符的基本用法,方便我们 ...

  6. Python学习教程(learning Python)--3.3.2 Python的关系运算

    如果if的condition不用布尔表达式来做条件判断而采用关系表达式,实际上关系表达式运算的结果要么是True要么是False.下面我们先了解一些有关关系运算符的基础知识,如下表所示. 做个小程序测 ...

  7. Python输入输出(IO)

    程序会有输入和输出,输入可以从标准输入或是从一个文件读入数据,程序的输出可以以一种友好可读的方式(human-readable)打印出来,或是写进一个文件,而标准输入和标准输出(键盘和显示器)在程序的 ...

  8. Python学习入门基础教程(learning Python)--3.3.2 Python的关系运算

    如果if的condition不用布尔表达式来做条件判断而采用关系表达式,实际上关系表达式运算的结果要么是True要么是False.下面我们先了解一些有关关系运算符的基础知识,如下表所示. 做个小程序测 ...

  9. 吾八哥学Python(五):Python基本数学运算

    今天我们学习Python里的基本数学运算方法,还是通过例子来练习吧! 加减乘除求余 #加法 print(12+34) #减法 print(30-10.0) #乘法 print(3*5) #除法 pri ...

随机推荐

  1. C#设计模式(0)-认识设计模式

    简介 世界上本没有路,走的人多了也就成了路:世界上本来没有设计模式.用的人多了,也就成了设计模式.所以,我们不是严格按照它的定义去执行,可以根据自己的实际场景.需求去变通.领悟了其中的思想,实现属于自 ...

  2. 快慢指针实现不依赖计数器寻找中位数(linked list)

    该方法在不借助计数器变量实现寻找中位数的功能.原理是:快指针的移动速度是慢指针移动速度的2倍,因此当快指针到达链表尾时,慢指针到达中点.程序还要考虑链表结点个数的奇偶数因素,当快指针移动x次后到达表尾 ...

  3. 在drawRect:方法中绘制图片,文字以及Core Graphics 框架的了解

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...

  4. swift UIButton边框添加阴影效果

    btn.layer.shadowOpacity = 0.8 //阴影区域透明度 btn.layer.shadowColor = UIColor.black.cgColor // 阴影区域颜色 btn. ...

  5. Vue事件处理

    前面的话 Vue事件监听的方式貌似违背了关注点分离(separation of concern)的传统理念.实际上,所有的Vue.js事件处理方法和表达式都严格绑定在当前视图的ViewModel上,它 ...

  6. 无法远程连接服务器上的mysql

    使用mysql管理工具连接服务器删过得mysql,显示连接被拒绝,但是在服务器上是可以登录mysql的. 无法远程连接通常以下几种情况: 首先,关闭mysql.        service mysq ...

  7. [转载]无旋treap:从好奇到入门(例题:bzoj3224 普通平衡树)

    转载自ZZH大佬,原文:http://www.cnblogs.com/LadyLex/p/7182491.html 今天我们来学习一种新的数据结构:无旋treap.它和splay一样支持区间操作,和t ...

  8. 两个List比较各自对象的属性相同的问题

    最近做checkbox默认勾选的时候,涉及到两个list直接比较彼此对象的Id属性是否相同的问题.能力有限,想到这个笨方法. 创建一个Bean: public class Bean { private ...

  9. Linq to Objects for Java 发布 1.0.1 版本

    现在 java 支持 linq 啦.比原生 stream api 更好用,功能更强大.现已发布 version 1.0.1 地址: https://github.com/timandy/linq. A ...

  10. webpack的四个核心概念介绍

    前言 webpack 是一个当下最流行的前端资源的模块打包器.当 webpack 处理应用程序时,它会递归地构建一个依赖关系图(dependency graph),其中包含应用程序需要的每个模块,然后 ...