After the lab, you should be proficient at
We'll practice writing several Python programs, each in their own text file. Name the files lab5.1.py through lab5.5.py.
Your programs will be graded on correctness, style, efficiency, and how well you tested them. Make sure you adhere to the good development and testing practices we discussed in class. Your code should be readable and your output should be useful and well-formatted.
After you've developed a correct solution to each program, restart IDLE or close and reopen the IDLE "shell" by running the program again (using F5), demonstrate that the program works using several good test cases, and save the output to a file named lab5.x.out, where x is the problem number.
lab5.2.py
. Then, define a function that takes as input
the speed limit and the clocked speed and returns the computed fine.
The driver of your program will print an appropriate message based on
the returned fine. Then, put the driver part of the program into a
main
function.
main
function.
translateLetter
that takes in a letter and key and
returns the translated version of the letter. Call the
translateLetter
function in the function you wrote for
the previous program.
In comments, briefly compare the readablity and efficiency of this program with the previous program.
game.py
that contains some useful game variables and functions.
Constant variables:
Assign the constants appropriate values.
Functions:
Save rainbowdice.py as lab5.5.py and
modify it to use the game
module and the
functions/constants you defined in the module. When you flip the
coin, test it against game
's variables HEADS and/or TAILS.
game
module. You can add more functions to the game
module, as
appropriate. The difficulty of the game will determine the amount of
extra credit you will receive.
Since you already have a solution for Craps, writing another solution
that uses the game
module (and adding other functions, as
appropriate) will earn you 5 extra credit points.
game
module in other code, the
interpreter created a .pyc
file. Delete that file so that
your output file isn't huge and doesn't contain strange characters.
turnin
directory.
(Review the UNIX handout if you don't
remember how to do that.)
printLab.sh
command. You should probably print from the
labs
directory.
Before you print, view the file to make sure it's not too long
or has weird characters in it from the .pyc
file. One
command to view the file is gv lab5.ps
Print the file using the lpr
command introduced in the
first lab.
Labs are due at the beginning of Friday's class. You should hand
in the printed copy at the beginning of class, and the electronic
version should be in the turnin
directory before 2:25
p.m. on Friday.
Ask well before the deadline if you need help turning in your assignment!