python第二節課
阿新 • • 發佈:2017-09-13
dia blog 序號 range left true 網絡工程 brush pri
import turtle turtle.shape(‘turtle‘) turtle.speed(5) turtle.color(‘green‘) var=1 while var == 1: for i in range(5): turtle.forward(200) turtle.right(144)
無限循環的五角星
from turtle import* for i in range(5): up() goto(0,-20*i) down() circle(20*i)
用循環畫同心圓
import turtle turtle.shape(‘turtle‘) turtle.speed(5) turtle.color(‘yellow‘) turtle.bgcolor(‘red‘) turtle.fillcolor(‘yellow‘) def my_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def my_star5(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() my_goto(-250,100) my_star5(100) my_goto(-150,75) my_star5(50) my_goto(-100,50) my_star5(50) my_goto(-50,25) my_star5(50) my_goto(-0,0) my_star5(50)
用函數畫了五個五角星
import turtle def draw_diamond(brad): brad.forward(100) brad.right(45) brad.forward(100) brad.right(135) def draw_art(): window=turtle.Screen() window.bgcolor("pink") brad=turtle.Turtle() brad.shape(‘turtle‘) brad.color(‘yellow‘) brad.speed(100) for i in range(1,37): draw_diamond(brad) draw_diamond(brad) brad.left(10) draw_art()
畫一朵花
r = input("請輸入學號:") print("學年:",r[:4]) print(r[4:6],":代表網絡工程") print("學號:",r[10:12])
輸入學號識別年級專業序號
r = input("請輸入數字:") print(‘星期‘,r)
星期幾
python第二節課