[Python教程] 一隻烏龜其實也很酷 (一、動起來)

課前準備:
Win7~Win10,MacOS,>=Ubuntu 16.04的電腦
Python 3.1.1 以上的 Python IDLE函數

1、烏龜?
烏龜是一種做圖模塊,在Python中能夠以下導入:code

import turtle

一、forward 函數
該函數使海龜畫出一條直線 x度import

import turtle
turtle.forward(100)

二、left 函數
該函數使海龜左轉 x度程序

import turtle
turtle.left(100)

三、right 函數
該函數使海龜右轉 x度im

import turtle
turtle.right(x)

2、製做程序co

import turtle    #導入模塊
for x in range(100):
    turtle.forward(x)    #前進x個單位
    turtle.left(90)    #左轉90度

畫出了一個螺旋正方形,正好100條線。

相關文章
相關標籤/搜索