Advanced_python

Advanced_python - June 11-13 2008 www.roboteducation.org 1...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: June 11-13 2008 www.roboteducation.org 1 IPRE 2008 WORKSHOP Advanced Pyt hon Kei t h O Har a keith.ohara@gatech.edu School of I nt er act i ve Comput i ng Geor gi a Tech June 11-13 2008 www.roboteducation.org 2 Pyt hon I nt er act i ve Cr oss- pl at f or m Looks l i ke pseudo- code I ndent at i on mat t er s Suppor t f or f unct i onal pr ogr amm i ng Lar ge col l ect i on of l i br ar i es Obj ect syst em bui l t on t op of f unct i ons Synt ax suppor t f or common dat a st r uct ur es Used by Googl e, Yahoo, NASA among ot her s June 11-13 2008 www.roboteducation.org 3 I nt er act i ng wi t h t he User wi t h Myr o ask(prompt) pr ompt user wi t h di al og box and r et ur n r esponse askQuestion(prompt, [choices]) pr ompt user wi t h di al og box and r et ur n r esponse raw_input(prompt) pr ompt user wi t h t ext i nt er f ace and r et ur n r esponse June 11-13 2008 www.roboteducation.org 4 Myr o and Fi l es pickAFile() pr ompt s user f or f i l e pickAFolder() pr ompt s user f or f ol der open(file, mode) open f i l e wi t h mode ( `r,`w,`a ) file.read(); file.readlines() r ead f i l e and r et ur n cont ent s as a st r i ng ( l i st of st r i ngs) string.split() Tur n st r i ng i nt o a l i st of st r i ngs based on whi t espace from myro import * f = open(pickAFile(), r) data = f.read().split() print data f.close() from myro import * f = open(pickAFile(), r) data = f.read().split() print data f.close() June 11-13 2008 www.roboteducation.org 5 Myr o Cont r ol Fl ow Const r uct s wait(seconds) pause f or seconds bef or e execut i ng next st at ement currentTime() r et ur ns t he cur r ent t i me i n seconds while timeRemaining(seconds): print "running..." execut e l oop f or at l east seconds for s in timer(seconds): print "running for", s, "..." l oop f or at l east seconds; s i s t he val ue of t he t i mer June 11-13 2008 www.roboteducation.org 6 Myr o Random Ut i l i t i es flipCoin() r et ur ns heads or t ai l s wi t h equal pr obabi l i t y heads() r et ur ns Tr ue 50% of t he t i me tails() r et ur ns Tr ue 50% of t he t i me pickOne(v1, v2, , vn) chose one val ue f r om t he val ues wi t h equal pr obabi l i t y randomNumber() r et ur n a uni f or m r andom number bet ween [ 0, 1) June 11-13 2008 www.roboteducation.org 7 random modul e r andom . uni f or m( l ow, hi gh) Fl oat : l ow <= x < hi gh r andom . r andi nt ( l ow, hi gh) I nt eger : l ow <= x <= hi gh r andom . choi ce( sequence) Random el ement of a sequence r andom . shuf f l e( sequence) Random l y shuf f l e a sequence June 11-13 2008 www.roboteducation.org 8 Scr i bbl er Musi c Random not es Use choice f unct i on import random notes = [440, 494, 523, 587, 659] for i in range(10): dur = random.random() freq = random.choice(notes) beep(dur, freq) June 11-13 2008 www.roboteducation.org 9June 11-13 2008 www....
View Full Document

Page1 / 32

Advanced_python - June 11-13 2008 www.roboteducation.org 1...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online