I210: Information Infrastructure
I (Intro to Programming) — Assignments (Fall)
Submit the following programs to Oncourse in your lab section each week.
á Ch. 1, Proj. 1 –
ice_cream_bad.py, ice_cream.py
á Ch. 1, Proj. 2 – name.py
á Ch. 1, Proj. 3 – quote.py
á Ch. 2, Proj. 1 –
variable_names.txt (3 legal names,
3 illegal names, 3 good legal names, 3 bad legal names, with explanations)
á Ch. 2, Proj. 2 – foods.py
á Ch. 2, Proj. 3 – average.py
á Ch. 2, Proj. 4 – tip.py
á Ch. 2, Proj. 5 – adventure.py
á
Ch.
3, Proj. 2 – flip.py
á
Ch.
3, Proj. 3 – guess.py
á
Ch.
3, Proj. 4 – nim.txt
á
Ch.
3, Proj. 5 – nim.py
Week 3 (Chapter 4):
á Ch. 4, Proj. 1 – vowels.py
á Ch. 4, Proj. 2 – tnirp.py
á Ch. 4, Proj. 3 –
rancard.py (Notice you need to use
tuples, not strings.)
á Ch. 4, Proj. 4 – cards.py (Ditto.)
á Ch. 4, Proj. 5 – jumble.py
á Ch. 4, 5 Points Extra
Credit – ixtlan.py
Given the following phrase tuple and word to be removed from
the phrase, write a program to create a string containing all the words in the
tuple, print it, and then create and print a string containing all of the words
in the tuple except the word you are supposed to remove. To receive credit you must use
"slice" functionality to extract the words from the phrase tuple when
creating the second, edited string.
This means you'll need to use start and stop indexes.
Here are the phrase tuple and word to be removed:
Phrase = ( "Now",
"Ixtlan", "we", "can",
"Ixtlan", "read", "this", "Ixtlan",
"sentence!" )
Remove = "Ixtlan"
Here is a sample run of ixtlan.py:
The unedited phrase is: Now Ixtlan we can Ixtlan read this
Ixtlan sentence!
The edited
phrase is:
Now we can read this
sentence!
á Ch. 5, Proj. 1 – faves.py
á Ch. 5, Proj. 2 – directions.py
á Ch. 4, Proj. 3 –
jumble2.py (Notice you need to use
a nested sequence for the hints, not a separate tuple.)
á Ch. 4, Proj. 4 – sort.py
á Ch. 4, Proj. 5 – geneology.py
á Ch. 6, Proj. 1 – scorefun.py
á Ch. 6, Proj. 2 – scorefun2.py
á Ch. 6, Proj. 3 –
first_second.py
á Ch. 6, Proj. 4 – guessfun.py
á Ch. 6, Proj. 5 –
jumblefun.py (There is a bug in
the code shown in the textbook:
The call to jumble() should have "the_word" as its argument,
not "word". You may
start from either Week 3Õs jumble.py or Week 4Õs jumble2.py, but do include
hints. If you start from Week 4's
version, with its list of tuples, you may want to change the definition of
random_word() to return a tuple instead of just a word, and assign its return
value to the_word, the_hint, and then change the definition of play() so you
pass in the_hint, in addition to the_word and the_jumble. It is acceptable to make these changes
from the textbook's statement of the problem. If you stick with the textbook's definitions of these
functions, you will probably need to change the main data structure from a list
of tuples to either a dictionary—in which case you can look up the hint
using the correct word as the key—or a pair of lists, one for the WORDS,
the other for the HINTS, and get the index to use in HINTS by looking up the
index of the word in WORDS, using something like WORDS.index(the_word).)
á Ch. 7, Proj. 1 –
scores_pickle.py (Start from
Chapter 5Õs "high_scores2.py", not "high_scores.py". If you move the main body of the code
into a function, be warned that the way he truncates the best scores list, by
slicing scores[:5] produces a new list, as a result of which the resulting sliced list will be
local to the function and will not propagate back to the calling routine. You can solve this by making score a
global variable—a bad way—or by changing the way the list is
truncated to use scores.pop()—the preferred way. If you donÕt use functions, this wonÕt
matter.)
á Ch. 7, Proj. 2 –
scores_text.py (DonÕt forget
str(), to turn an int into a string.
If you read the name back in with readline(), it will have a newline on
the end that you can get rid of with strip()—donÕt forget that strip()
produces a new string because strings are immutable, so youÕll need an
assignment statement. When you
write the values out with write() youÕll need to put your own newlines on each
line.)
á Ch. 7, Proj. 3 – trivia.py
á Ch. 7, Proj. 4 –
multitrivia.py
á Ch. 7, Proj. 5 –
python_files.trv
Week 7:
á Review & Midterm
Exam. No lab. No assignment due.
Week 8 – Part 1 (Review, Assigned
Tuesday, Due Thursday):
This mid-week assignment will replace the second lowest
lab score for the semester, as an extra incentive to complete it on time and as
a way to improve your overall grade.
As such, late submissions will not be allowed. This will let us review these programs in Thursday's
lecture.
Note: In all of this week's projects, the output must look
like the input. No extra lines, no
extra spaces, no embedding in a Python data structure, just an accurate copy of
the source file's text. You need
only worry about reading, displaying, or copying plain text files, and you may
assume the user provides the type of input you ask for.
á Proj. 1 a, b, c – Ask for a
filename and print that file to the screen, using no functions or exception
handling.
o 1a – printfile1a.py – Use no loops.
o 1b
– printfile1b.py – Read one line at a time and use a loop. (You must figure out a way to avoid
print blank lines between the lines of the file you are reading.)
o 1c – printfile1c.py
– Read one character at a time and use a loop. (You must figure out a way to avoid printing spaces between
all the characters.)
á
Proj.
2 a, b, c – Same as Proj. 1, but use three functions: open_file(file_name,
access_mode), print_file(file_object), and main(). There must still be no exception handling.
o 2a – printfile2a.py
– Like 1a, the print_file() function must not use a loop.
o 2b – printfile2b.py
– Like 1b, print_file() function must read one line at a time and use a
loop.
o 2c – printfile2c.py
– Like 1c, the print_file() function must read one character at a time
and use a loop.
á
Proj.
3 a, b, c – Same as Proj. 2, but now add IOError exception handling for
the file open() and SystemExit exception handling for main().
o 3a – printfile3a.py
– Like 2a, the print_file() function must not use a loop.
o 3b – printfile3b.py
– Like 2b, print_file() function must read one line at a time and use a
loop.
o 3c – printfile3c.py
– Like 2c, the print_file() function must read one character at a time
and use a loop.
á
Proj.
4 a, b, c – Same as Proj. 3, but also ask for a character to replace and
another character to replace it with during printing, then change print_file()
into print_file_with_replacement(file_object, in_char, out_char) and replace
every occurrence of in_char with out_char when printing to the screen.
o 4a – printfile4a.py
– Like 3a, the print_file_with_replacement() function must not use a
loop.
o 4b – printfile4b.py
– Like 3b, print_file_with_replacement() function must read one line at a
time and use a loop.
o 4c
– printfile4c.py – Like 3c, the print_file_with_replacement()
function must read one character at a time and use a loop.
Week 8 – Part 2 (Review, Assigned in Lab, Due following Tuesday like usual):
Note: In all of this week's projects, the output must look
like the input. No extra lines, no
extra spaces, no embedding in a Python data structure, just an accurate copy of
the source file's text. You need only
worry about reading, displaying, or copying plain text files, and you may
assume the user provides the type of input you ask for.
á Proj. 5 1, 2, 3 – Ask for a
source filename and a target filename.
Then copy the source file to the target file using the open_file()
function of problems 3 and 4, a new copy_file(source_file, target_file)
function, and a main() function, with the same exception handling as problems 3
and 4.
o 5-1 – copyfile1.py – The copy_file() function must not use a loop.
o 5-2
– copyfile2.py – The copy_file() function must read one line at a
time and use a loop.
o 5-3 – copyfile3.py –
The copy_file() function must read one character at a time and use a loop.
á
Proj.
6 1, 2, 3 – Same as Proj. 5, but also ask for a character to replace and
another character to replace it with during the file copying. Replace copy_file() with a new
copy_file_with_replacement(source_file, target_file, in_char, out_char) into
which you must pass the two file objects and the two characters (the
"in_char" should be the character that is already in the file and
which is being replaced; the "out_char" should be the character that
is replacing "in_char" when the file is copied).
o 6-1 – changefile1.py
– Like 5-1, the copy_file_with_replacement() function must not use a loop.
o 6-2 – changefile2.py
– Like 5-2, copy_file_with_replacement() function must read one line at a
time and use a loop.
o 6-3 – changefile3.py
– Like 5-3, copy_file_with_replacement() function must read one character
at a time and use a loop.
á Ch. 8, Proj. 1 – critter.py
á Ch. 8, Proj. 2 –
spaceship.py (Show how to use no
parameters, each single parameter, and both parameters to instantiate a ship.)
á Ch. 8, Proj. 3 –
player.py (Define the Player class
so a player object can be created with a unique name, maximum inventory size,
and initial list of items in the playerÕs inventory. Create a default player; have the player take items; try to
add more items than the player can hold; have the player drop an item; have the
player take an item that was not in the inventory previously. Call the playerÕs inventory function
when the player is first instantiated and again after each change to the
inventory. Finally, create an
instance of a player using non-default values for the name, maximum number of
items, and initial item list.)
á Ch. 8, Proj. 4 – spaceship2.py
á Ch. 8, Proj. 5 – tv.py
Week 10 (Chapter 9, Projects 1-3):
á Ch. 9, Proj. 1 – blackjack2.py
á Ch. 9, Proj. 2 –
weapon.py (Instantiate a Sword that
causes 5 points of damage, and swing it twice.)
á Ch. 9, Proj. 3 –
weapons.py (Instantiate a Sword
that causes 5 points of damage and swing it twice. Then instantiate a Crossbow that causes 10 points of damage
and fire it twice in a row, reload it twice in a row, fire it, reload it, and
fire it, all in that order.)
Week 11 (Chapter 9, Projects 4-5):
á Ch. 9, Proj. 4 –
blaster.py (Instantiate an Alien
that starts with 5 units of health and a Player that blasts it 6 times. To be sure all your code is working,
try instantiating the Player with 4, 5, and 6 units of ammo, and pay attention
to the results.)
á Ch. 9, Proj. 5 –
blackjack3.py (Take all players'
bets before dealing any cards.)
á Ch. 10, Proj. 1 –
color.py (On Macs, the button
background does NOT change color.
In addition to changing the "bg" widget option, also set the
button's text to the color name.)
á Ch. 10, Proj. 2 – grid.py (+5 points
extra credit if your program can display a grid of an arbitrary NUM_COLUMNS x NUM_ROWS
using an appropriate window size; i.e., a window size that is only a little bit
larger than is actually needed to display the gridded text.)
á Ch. 10, Proj. 3 – rps.py (Be sure to handle the problem case
when a user clicks the "Fight!" button without having made their
choice between Rock, Paper, and Scissors.
Make sure the text of the Rock, Paper, and Scissors radio buttons is
capitalized. Be sure to show the
outcome of the match. You can make the logic a bit easier on yourself if you
first deal with the case when the computer's choice matches the player's
choice, and thus produces a draw, regardless of what they actually selected.)
á Ch. 10, Proj. 4 –
burger.py (A measly two points
will be deducted if the grammar, including punctuation, is incorrect. You may use the "Oxford
comma" or not.)
á Ch. 10, Proj. 5 – password.py
á Review. Thanksgiving. No lab. No
assignment due. (I suggest you get
a jump on next week's reading and programming, as there's a lot to do!)
á Ch. 11, Proj. 1 –
avalanche.txt
á Ch. 11, Proj. 2 –
avalanche.py (Rocks can just fall
straight down and always start in random locations. Add any background you want; "wall.jpg" or "wall.bmp"
is okay. Be sure to turn in whatever
background you use if it is different from what the book provides.)
á Ch. 11, Proj. 3 –
avalanche2.py
á Ch. 11, Proj. 4 – cpong.txt
á Ch. 11, Proj. 5 –
cpong.py (For consistency, place
the paddle on the left, 10 pixels in from the edge, and place new balls on the
right edge. Make the balls start
at random heights, with random dy values between -4 and 4, inclusive, and
random dx values between -1 and -3.
Hint: If you have trouble
with a flurry of balls being created at once, it's probably because when the
ball bounces, under certain conditions, it is still on top of the paddle, which
can cause it to bounce again and again and again... This should suggest an easy fix. Hint: The
paddle width is 16 pixels; the ball width is 12 pixels. +5 points extra
credit if you implement an accurate score functionality and display where the
background image indicates. Score
one point per ball successfully bounced with the paddle.)
á