{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

interpreter-6

interpreter-6 - RobotInterpreters CMSC 143 Keith OHara...

This preview shows pages 1–9. Sign up to view the full content.

Sep 20 2010 CMSC143 - O'Hara 1 1 CMSC 143 Robot Interpreters Keith O’Hara [email protected]

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

View Full Document
Sep 20 2010 CMSC143 - O'Hara 2 Announcements Robot Behavior Lab due Today (20 th ) Team Performance due in a Week (27 th )
Sep 20 2010 CMSC143 - O'Hara 3 Quiz (matching) def b ( x ): if bool1(x): if bool2(x): z() def a ( x ): if bool1(x): z() if bool2(x): z() def one ( x ): if bool1(x) or bool2(x): z() def c ( x ): if bool1(x): pass else : z() def three ( x ): if bool1(x) and bool2(x): z() def two ( x ): if not bool1(x): z()

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

View Full Document
Sep 20 2010 CMSC143 - O'Hara 4 Factorial Factorial Function 6! = 6 * 5 * 4 * 3 * 2 * 1 7! = 7 * 6 * 5 * 4 * 2 * 2 * 1 = 7 * 6! 9! = 9 * 8 * 7 * … * 2 * 1 10! = 10 * 9 * 8 * … * 2 * 1 = 10 * 9! 2! = 2 * 1 1! = 1 0! = 1
Sep 20 2010 CMSC143 - O'Hara 5 Factorial x! = x * (x-1)! # number should be greater than or equal to zero def factorial( number ): if number < 1: return 1 else: f = number *factorial( number - 1) return f factorial(4)

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

View Full Document
Sep 20 2010 CMSC143 - O'Hara 6 Tracing Factorial def factorial( number ): if number < 1: return 1 else: f = number *factorial( number - 1) return f factorial(4) Top-level factorial number = 4; f = 4 * ? factorial number = 3; f = 3 * ? factorial number = 2; f = 2 * ? factorial number = 1; f = 1 * ? factorial number = 0 number = 4; f = 4 * 6 number = 3; f = 3 * 2 number = 2; f = 2 * 1 number = 1; f = 1 * 1
Meta-programs Programs than input and output programs Compilers; Interpreters Interpret stream of text (python, lisp) or images (piet) Sep 20 2010 CMSC143 - O'Hara 7 http://www.dangermouse.net/esoteric/piet/piet_factorial_ big.png (defun factorial (n) (if (<= n 1) 1 (* n (factorial (- n 1))))) def factorial( number ): if number < 1: return 1 else: return number *factorial( number - 1)

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

View Full Document
Sep 20 2010 CMSC143 - O'Hara 8 A Python Robot Interpreter A program to control the robot using keyboard Give it a list of commands to execute f: forward b: backward r: right l: left a: beep a Continue until quit is entered Enter Commands: ffblr Enter Commands: bbrlraaaabbbbbb Re-enter shorter command, too long Enter Commands: bbrlr Enter Commands: quit
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern