I210:
Information Infrastructure I (Intro to Programming) — Assignments
Submit
the following programs to Oncourse in your lab
section each week. Required
assignments are in black; programs in blue are for
extra credit only.
Week
1
(Chapters 1 & 2):
á
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
Week
2
(Chapter 3):
á
Ch. 3, Proj.
1 – score.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 – 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!
Week
4
(Chapter 5):
á
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
Week
5
(Chapter 6):
á
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).)
Week
6
(Chapter 7):
á
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
á
Review & Midterm
Exam. No lab. No assignment due.
Week
8
(Chapter 8):
á
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
9
(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
10
(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.)
Week
11
(Chapter 10):
á
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 (See
if you can get your program to 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
Week
12
(Chapter 11):
Download and use the .bmp files in these project files instead of
the .jpg files provided with the book.
á
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.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.
See if you can implement an accurate score functionality and display it
where the background image indicates.
Score one point per ball successfully bounced with the paddle.)
Week
13
(read ahead to Chapter 12):
á
Review. Thanksgiving.
No lab. No new
assignment. (I suggest you get a
jump on next week's reading and programming, as there's a lot to do!)
Week
14
(Chapter 12):
Download and use the .bmp files in these project files
instead of the .jpg files provided with the book.
á
Ch. 12, Proj.
1 – cpong2.txt
á
Ch. 12, Proj. 2 – cpong2.py (Start with a single Bounce_Ball.
You may want to only create a new ball when a Bounce_Ball has been hit by the paddle, just to make the
game a little easier to play.)
á
Ch. 12, Proj.
3 – swarm.txt
á
Ch.
12, Proj. 4 – swarm.py (Don't let the missiles fire too fast,
as in AstroCrash. Play missile and explosion sounds. Whether you play theme music in the background, and what
that theme music is is up to you. And you can use whatever background you
want. Be sure to turn in whatever
music and background you use if they are different from what the book
provides.)
á
Ch.
12, Proj. 5 – swarm2.py
á
Final Exam in lab. No new assignment.
|
|
For more information, contact: Larry Yaeger |