Lab 6 - Programming with Python
Evolution and Learning in Computational and Robotic Agents
MSE 2400 Dr. Tom Way
Introduction
- In this lab project, you will gain the necessary skills to accomplish
Lab 7 during which you will create and modifiy various forms of classifiers. Along the
way you will
learn how to write a computer program using the Python programming language
by first working through an excellent online tutorial and then by crafting a
number of increasingly more involved programs of your own. The dual goals
for this lab are for you to achieve a degree of confidence in solving
problems by writing code using the Python language AND to gain a deeper
understanding of writing code, including what is possible and what is not.
- Python is a widely used programming language that is used for creating
web applications and for doing natural language processing. Companies like
Google use Python extensively to provide their online services. A Python
program is made up of one or more text files that contain the step-by-step
Python instructions to make a computer do what you want it to do.
- For this lab, you will start with "visual programming" that
uses a graphical interface. As you become more advanced in your programming
skill, you will create programs by typing rather than dragging and dropping.
- You may work alone or with a partner for this lab.
Worth
Due
- At the end of the lab session designated for this work, or at a time
mutually agreed to by you and the instructor.
Lab Steps
Part 1 - Why Write Code?
-
Go to Code.org and
watch the video.
(We may watch this as a class.)
Part 2 - Hour of Code
- Go to the Hour
of Code on the Code.org page.
Watch the introductory video.
- Complete all 20 puzzles.
- Demonstrate your results to the instructor or TA and acquire his or her
initials here: ____________
- ALTERNATIVE TO INITIALS: If you do this work on your own, briefly
describe here in writing what you did and what you learned:
Part 3 - Flappy Code
-
Go to the Flappy Code project
on Code.org. Watch the introductory video.
-
Complete all 10 puzzles.
-
Demonstrate your results to the instructor or TA and acquire his or her
initials here: ____________
-
ALTERNATIVE TO INITIALS: If you do this work on your own,
briefly describe here in writing what you did and what you learned:
Part 4 - Lightbot
-
Go to the Lightbot project on Code.org.
-
Complete all the puzzles in Basics, Procedures and Loops.
-
Demonstrate your results to the instructor or TA and acquire his or her
initials here: ____________
-
ALTERNATIVE TO INITIALS: If you do this work on your own,
briefly describe here in writing what you did and what you learned:
Part 5 - Gaining mad skills in Python
- Go to Computer Science Circles (http://cscircles.cemc.uwaterloo.ca/)
and create a free account.
- Complete the following lessons:
- 0: Hello!
- 1: Variables
- 1E: Errors
- 2: Functions
- 2X: Extra Practice
- 3: Comments and Quotes
- 4: Types
- 5: Input
- 6: If
- 9: Else, And, Or, Not
- 10: def
- 13: Lists (Arrays)
- Demonstrate your results to the instructor or TA and acquire initials here: ____________
- ALTERNATIVE TO INITIALS: If you work through this tutorial on your own,
briefly describe here in writing what you did and what you learned:
Part 6 - Verify that Python is Installed
- In this lab and Lab 7, you will use the IDLE Python editor. Make sure it is installed
on your laptop. If it isn't installed, follow the instructions for
installing Python and NLTK here.
Part 7 - Writing your first program
- Open IDLE and write a
"hello world" program.
- Run the program (which means you need to save it first).
- Demonstrate your "hello world" program to the instructor or TA, and
acquire initials here: __________
- ALTERNATIVE TO INITIALS: If you do this work on your own,
briefly describe here in writing what you did and what you learned:
Part 8 - Understanding an existing
program
- Download and save the numberguess.py
program file. Alternately, you can copy it and paste it into a new document
in IDLE.
- Download and save in the same folder the
insults.txt file for use with the program.
- Open the program in IDLE and run it.
- Add comments to the program (a line starting with the "#" character
indicates a comment) that describe what various lines or sections of code
are doing. After adding comments, make sure the program still works
correctly by saving it and running it again.
- Modify the insults.txt file by adding more insults or even making
the "insults" more positive rather than negative.
- Save the revised program and insults file, and show them to the instructor or TA, and have
them sign their initials here: __________
- ALTERNATIVE TO INITIALS: If you do this work on your own,
briefly describe here in writing what you did and what you learned: