Transcription of 파이썬 #1 - smartrobotmarket.com
1 #1 API >>> print hello >>> print hello >>> print hamster ( ) >>> print hello >>> print hamster >>> print hello + hamster >>> print hello >>> print hamster >>> print hello + hamster >>> print hello , hamster + hamster ? , hamster ? >>> print hello >>> print hamster >>> print hello + hamster >>> print hello , hamster >>> print hello\nhamster >>> print hello >>> print hamster >>> print hello + hamster >>> print hello , hamster >>> print hello\nhamster >>> print hello.
2 Hamster ------------------------------ title ------------------------------ ------------------------------ title ------------------------------ >>> print - *30; print title ; print - *30 (;) ^^;; ------------------------------ title ------------------------------ >>> print - *30; print title ; print - *30 ------------------------------ I m hamster ------------------------------ ------------------------------ title ------------------------------ >>> print - *30; print title ; print - *30 ------------------------------ I m hamster ------------------------------ ------------------------------ I m albert ------------------------------ >>> line = - *30 >>> name = hamster >>> print line; print I m + name; print line , , (I m hamster I m albert) ?
3 >>> line = - *30 >>> name = hamster >>> print line; print I m + name; print line ------------------------------ I m hamster. Are you albert? ------------------------------ >>> line = - *30 >>> name = hamster >>> print line; print I m + name; print line ------------------------------ I m hamster. Are you albert? ------------------------------ ------------------------------ I m hamster ------------------------------ >>> line = - *30 >>> name = hamster >>> print line; print I m %s % name; print line %s name %d, %s . %s PPT ------------------------------ I m hamster. Are you albert?
4 ------------------------------ %s %s ------------------------------ I m hamster. Are you albert? ------------------------------ >>> line = - *30 >>> name1 = hamster >>> name2 = albert >>> print line; print I m %s. Are you %s % (name1, name2); print line hamster albert % %s %s tuple >>> sentence = hello hamster. hamster hamster 100 ? >>> print sentence[6:13] >>> sentence = hello hamster. >>> print sentence[6:13] >>> print sentence[6:-1] hamster. >>> sentence = hello hamster.
5 >>> print sentence[6:13] >>> print sentence[6:-1] >>> print sentence[6:] hello >>> sentence = hello hamster. >>> print sentence[6:13] >>> print sentence[:5] >>> print sentence[6:-1] >>> print sentence[6:] >>> sentence = hello hamster. >>> print sentence[6:13] >>> print sentence[:5] >>> print sentence[6:-1] >>> print sentence[6:] hello albert. hello hamster hello albert >>> sentence = hello hamster. >>> print sentence[6:13] >>> print sentence[:5] >>> print sentence[6:-1] >>> print sentence[6:] hello albert. >>> print sentence[:6] + albert + sentence[-1] name = raw_input( Enter name: ) print I m %s. % name C:\Python27 py ASCII.
6 ^^;; C:\Python27 >>> name = raw_input( Enter name: ) I m ??? ~ ^^ from import Hamster # create a hamster robot = Hamster() (30, 30, 1) ( ) ( ) , from import Hamster # create a hamster robot = Hamster() (30, 30, 1) # for a sample hamster () (1000) 1 msec from import Hamster # create a hamster robot = Hamster() (-30, -30, 1) # for a sample hamster () (1000) , (-30, 30, 1) (0, 30, 1) (20, 50, 1) for i in range(10): (30, 30, 1) for for (:).
7 (for, while, if ) for(i=0;i<10;++i) ^^ in range .. 1 ( ) 4 4 4 ^^;; while True: proximity = () print proximity while True: proximity = () if proximity[0] > 40: (-30, -30) else: (30, 30) , , (LEFT_LED, RIGHT_LED, SECONDS) LED , LED , ( ) (LEFT_LED, RIGHT_LED, SECONDS) LED 1~7 ) ( , , 3) while True: proximity = () if proximity[0] > 40 or proximity[1] > 40: (-30, -30) else: (30, 30) while True: leftFloor = ( ) rightFloor = ( ) if leftFloor < 50 or rightFloor < 50: (0, 0) else: (30, 30) A4 A4 , if : ?
8 ??? elif : ???? else: ???? def function(arg1, arg2): .. return .. def motors(left, right, seconds=0): ( , left) ( , right) if seconds > 0: (seconds * 1000) ( , 0) ( , 0) API API API .. ^^;; -100 ~ 100 % -100 ~ 100 % 0 ~ Hz 0 ~ 7 0 ~ 7 0 ~ 88 -128 ~ 0 dB 0 ~ 255 0 ~ 255 0 ~ 255 0 ~ 255 -32768 ~ 32767 0 ~ 65535 -40 ~ 88 oC 0 ~ 100 % robot = Hamster() (, index) (, index, value) API 2 ^^;; , , , C, C++ API robot = Hamster() (, index) (, index, value) ( ) index value Acceleration 1 index 0 Acceleration x , y , z 3 3 x 0, y 1, z 2 robot = Hamster() () (, value) 0 index index index 0 def move(left, right, seconds=0): def light(left, right, seconds=0): def beep().
9 1) 2) 3) 4) 5) 6)