您的位置:首页 > 编程语言 > Python开发

Python基本语法熟悉,turtle图形函数画图

2017-12-28 20:06 776 查看
1.对Python基本语法的简单运用,小小的文字游戏

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