Cov txheej txheem:

Kawm paub Code Siv Python Turtle: 4 Cov Kauj Ruam
Kawm paub Code Siv Python Turtle: 4 Cov Kauj Ruam

Video: Kawm paub Code Siv Python Turtle: 4 Cov Kauj Ruam

Video: Kawm paub Code Siv Python Turtle: 4 Cov Kauj Ruam
Video: Leslie Kean on David Grusch (UFO Whistleblower): Non-Human Intelligence, Recovered UFOs, UAP, & more 2024, Kaum ib hlis
Anonim
Kawm paub Code Siv Python Turtle
Kawm paub Code Siv Python Turtle

Hauv qhov kev qhia no peb yuav qhia rau lub ntiaj teb kev lom zem ntawm kev siv Python, tshwj xeeb yog Tsev Qhua Turtle.

Peb xav tias koj tsis muaj kev paub ua ntej coding. Yog tias koj xav paub ntau ntxiv, peb xav kom nyeem tus kws sau phau ntawv:

www.amazon.com/by-Omar-Silva-Zapata/e/B00Y…

Kauj ruam 1: Yuav tsum tau ua

Yuav tsum muaj
Yuav tsum muaj

Yuav tsum muaj dab tsi?

Ib lub PC lossis Raspberry Pi nrog Python 2.7 lossis ntau dua tau teeb tsa.

Zoo kawg Python tuaj yeem ua haujlwm hauv txhua lub PC hauv feem ntau ntawm kev ua haujlwm. Yog xav paub yuav ua li cas rub tus nab npawb hauv koj lub cuab yeej mus rau:

www.python.org/

Hauv qab rub tawm cov ntawv qhia zaub mov, xaiv koj lub operating system thiab ua raws cov lus qhia teeb tsa.

Kauj ruam 2: Siv IDLE Editor

Siv IDLE Editor
Siv IDLE Editor

Python's IDLE (Kev Txhim Kho Kev Txhim Kho thiab Kawm Ib puag ncig) yog tus kho peb yuav siv hauv qhov kev qhia no tab sis muaj ntau ntxiv. Ntawm Robo-Geek peb nyiam qhov ntawd yooj yim to taub, nws tau ua txoj haujlwm tiav thiab nws tsis hem thawj tus thawj coders. Yog xav paub ntau ntxiv txog IDLE, thov txheeb xyuas:

docs.python.org/2/library/idle.html

Tom qab Python teeb tsa, peb yuav tsum qhib IDLE.

Yuav ua li cas qhib IDLE editor yuav nyob ntawm seb lub operating system twg tau siv. Rau qhov yooj yim qhov seem ntawm kev qhia yuav xav tias koj siv lub PC nrog Windows 10. Yog tias tsis yog, tsis txhob txhawj ntau dhau, tshawb nrhiav internet sai thiab koj yuav pom ntau cov kev pab.

Hauv Windows, tsuas yog mus rau Start Menu, saib Python nplaub tshev thiab xaiv IDLE icon.

Yog ua tiav koj yuav pom lub vijtsam uas qhia hauv daim duab rau theem no. Thawj kab hauv qab cov ntawv qhia zaub mov, hais tias Python version koj tab tom siv.

Kauj Ruam 3: Thawj Kab Ntawm Txoj Cai - Ntshuam nab nab

Thawj Kab Ntawm Txoj Cai - Ntshuam nab nab
Thawj Kab Ntawm Txoj Cai - Ntshuam nab nab
Thawj Kab Ntawm Txoj Cai - Ntshuam nab nab
Thawj Kab Ntawm Txoj Cai - Ntshuam nab nab

Tam sim no yog qhov txaus siab ntawm qhov qhia. Cia peb mus rau code:

Ua ntej peb yuav tsum hu rau lub tsev qiv ntawv peb yuav siv, qhov no yog ua tiav siv cov lus txib ntshuam. Ntaus cov hauv qab no thiab nias Enter.

ntshuam vaub kib

Daim ntawv ceeb toom IDLE yuav hais txog txiv kab ntxwv nab nab hais kom ua ntshuam. Tom ntej no peb yuav tsum tsim cov khoom vaub kib, ntaus cov cai hauv qab no thiab nias Enter

t = vaub kib. Turtle ()

Thaum koj ua tiav nias Enter, yog tias tsis muaj cov kab lus sau lossis sau tsis raug, lub vijtsam tshiab uas qhia txog daim duab peb sab hauv nruab nrab ntawm cov keeb kwm yav dhau dawb yuav pom zoo li hauv daim duab rau qib no. Muab lub qhov rais cais thiab kho qhov rai qhov ntev kom lawv haum ib sab.

Kauj Ruam 4: Tsim Square

Tsim Square
Tsim Square
Tsim Square
Tsim Square
Tsim Square
Tsim Square

Daim duab peb sab me me nyob hauv nruab nrab ntawm lub vijtsam sawv cev rau tus vaub kib.

Txhawm rau kom tus vaub kib txav mus rau tom ntej, ntaus cov hauv qab no:

twb.fd (100)

Daim ntawv ceeb toom, tus vaub kib tau txav mus 100 pixels hauv qhov kev taw qhia tus vaub kib tau taw tes. Tam sim no cia peb tig lub vaub kib 90 degrees kom taw tes:

tsi (90)

Tam sim no tus vaub kib poob qis, peb yuav sau ob peb lo lus txib ntxiv kom ua tiav lub xwmfab:

t.fd (100) t.rt (90) t.fd (100) t.rt (90) t.fd (100)

Zoo heev koj tau ua tiav koj thawj lub xwmfab!

Tam sim no cia pib dua, nqa tus vaub kib tsev thiab tshem qhov screen los ntawm:

t.home ()

t.clear ()

Xwb, peb tuaj yeem kos cov xwm txheej kom zoo dua qub los ntawm kev siv lub voj:

rau kuv hauv thaj tsam (4):

t.fd (100) t.rt (90)

Peb tuaj yeem hloov xim ntawm tus vaub kib mus rau xiav los ntawm:

t.color ('xiav')

Thiab tau kawg peb tuaj yeem ua ntau yam ntxiv, qhov kev qhia no tsuas yog ua rau koj saj thiab ua rau koj mus. Yog xav paub ntxiv tshawb xyuas Python Turtle cov ntaub ntawv, docs.python.org/2/library/turtle.html

Kuj xav txog kev yuav tus sau phau ntawv:

www.amazon.com/by-Omar-Silva-Zapata/e/B00Y…

Zoo tshaj plaws.

Pom zoo: