Python基本语法熟悉,turtle图形函数画图
2017-12-28 20:06
776 查看
1.对Python基本语法的简单运用,小小的文字游戏
2.turtle随机画图小程序
import time print "Welcome to the space" password = raw_input("Please input your password: \n") while password != "123456": print "The password is worng , please input it again" password = raw_input("Please input your password: \n") print " " print "Welcome to the ship , you have a lot of choices\n" print "a-fire cannon" print "b-break the ship" print "c-exit" print " " time.sleep(1) conductor = raw_input("please input your conductor\n") while conductor != "c": if conductor == "a": T1 = raw_input( "Are you sure? (y/n)\n") if T1 == "y": print "fire!" time.sleep(1) print "boom!" time.sleep(1) conductor = raw_input("ok,please input your another conductor\n") elif T1 == "n": conductor = raw_input("ok,please input your another conductor\n") elif conductor == "b": T1 = raw_input( "Are you sure? (y/n)\n") if T1 == "y": print "dong!" time.sleep(1) print "dong!" time.sleep(1) print "bye" conductor = "c" elif T1 == "n": conductor = raw_input("ok,please input your another conductor\n") else: print "your conductor is invaild" conductor = raw_input("please input your conductor\n") print " " print "byebye"
2.turtle随机画图小程序
import turtle import random def drawshape(sides, length): angle = 360.0 / sides for sides in range(sides): turtle.forward(length) turtle.right(angle) def moveTurtle(x, y): turtle.penup() turtle.goto(x,y) turtle.pendown() def drawsquare(length): drawshape(4,length) def drawtriangle(length): drawshape(3,length) def drawcircle(length): drawshape(360, length) def drawrandom(): x = random.randrange(-200, 200) y = random.randrange(-200, 200) length = random.randrange(75) shape = random.randrange(1, 4) moveTurtle(x, y) if shape == 1: drawsquare(length) elif shape == 2: drawtriangle(length) elif shape == 3: length = length % 4 drawcircle(length) for shape in range(100): drawrandom() turtle.done()
相关文章推荐
- Python基本语法_函数属性 & 参数类型 & 偏函数的应用
- Python 详解基本语法_函数_返回值
- Python3 基本语法四 函数 匿名函数 闭包
- MATLAB画图入门篇--各种基本图形绘制的函数与实例
- matlab画图入门篇--各种基本图形绘制的函数与实例【转载】
- Python 2.7 学习笔记 基本语法和函数定义
- turtle图形函数画图
- 4-python基础python的基本语法之标准输入函数
- 我的Python学习之路之基本语法-函数
- python 学习笔记(一)通过做题来熟悉python 的基本语法
- Python笔记——基本语法:标识符、数据类型、变量、运算符及表达式/编码风格
- python中的最最最基本语法(1)
- 正则表达式的基本语法和在Python下的使用
- python基础语法(6) 函数1
- Python系列之二_Python基本语法
- Python GUI:高级作图tkinter模块的常用函数基本的动画和事件绑定
- python:3:列表基本用法及相关函数(1)
- Python基本语法,python入门到精通[二]
- Python turtle 库 画图 彩色螺旋线五角星太阳花