• 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. node-xlsx

    1.安装 必要组件 npm install node-xlsx -S /*Babel默认只转换新的JavaScript句法(syntax),而不转换新的API,比如Iterator.Generator ...

  2. C# 将数据表导出到Excel通用方法

    DataGrid dg = new DataGrid(); dg.DataSource = dt; dg.DataBind(); Response.Clear(); Response.Buffer = ...

  3. ida和idr机制分析(盘符分配机制)

    # ida和idr机制分析 ida和idr的机制在我个人看来,是内核管理整数资源的一种方法.在内核中,许多地方都用到了该结构(例如class的id,disk的id),更直观的说,硬盘的sda到sdz的 ...

  4. Head First 设计模式 第4章工厂模式

    第4章 工厂模式 在介绍工厂模式之前,先让我们来看一个例子. 这里有一个Pizza类,用来生产pizza,并返回对象,具体代码如下: package com.ek.factory.simple; im ...

  5. Bat脚本自动卸载软件-静默执行

    通过Bat脚本卸载软件,原理是得到某软件的ProductCode,然后通过MsiExec.exe命令卸载软件,下面是卸载一个产品的基本代码示例: set ML4.0HF4Name=Product4.0 ...

  6. python之禅 the zen of python

    >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is ...

  7. [填坑]树上差分 例题:[JLOI2014]松鼠的新家(LCA)

    今天算是把LCA这个坑填上了一点点,又复习(其实是预习)了一下树上差分.其实普通的差分我还是会的,树上的嘛,也是懂原理的就是没怎么打过. 我们先来把树上差分能做到的看一下: 1.找所有路径公共覆盖的边 ...

  8. [算法题] Remove Duplicates from Sorted Array ii

    题目内容 本题来源LeetCode Follow up for "Remove Duplicates": What if duplicates are allowed at mos ...

  9. angular基础

    =>是es6语法中的arrow function 举例: (x) => x + 6 相当于 function(x){ return x + 6; } >>> 是无符号移位 ...

  10. 时序分解算法:STL

    1. 详解 STL (Seasonal-Trend decomposition procedure based on Loess) [1] 为时序分解中一种常见的算法,将某时刻的数据\(Y_v\)分解 ...