|
CS 140: Introduction
to Computer Programming
HOMEWORK #7
due Friday, Nov 2 by
5:00pm
Guidelines
for completing and submitting homework
Refer to the first two paragraphs on the Grading Info
page for all the details. Briefly,
you may not collaborate with your
classmates while writing homework
programs. However, you may certainly
consult Spencer on Thursday evenings or
Dr. V on Friday afternoons as you create
your programs. (Email your program
to me first to check that I'm in the
office.) Other QRC mentors may also
be able to help out, depending on their
experience with Python. Once you
have completed your program, or made as
much progress as possible, email your
program as an attachment to svandervelde@stlawu.edu.
Assignment
To begin, create a new document in Komodo
and include these comments at the top
# Your
full name
# Homework #7, Nov 2, 2012
# Individuals providing
assistance, if any
Then save your file using the format LastnameHW7.py.
This week you will write a program that
keeps track of (hypothetical) college
rankings. To begin, define a list as
colleges =
["Allegheny", "Bates", "Bucknell",
"Carleton", "Colby", "Colgate",
"Denison", "Dickinson", "Drew",
"Gettysburg", "Hamilton", "Holy
Cross", "Kalamazoo", "Kenyon",
"Macalester", "Middlebury",
"Muhlenberg", "Skidmore", "St.
Lawrence", "Trinity", "Vassar",
"Wesleyan", "Wheaton", "Wooster"]
You can just cut and paste this line into
your program; no need to retype it.
Now perform the following two operations on
your list.
-
To
begin, we will create a random
reordering of this list. (College
rankings are essentially random,
right?) So initialize a new list rankings
to be
the empty list.
- Now set up a for j in
range loop
that will execute as many times as there
are names in your list. During
each pass through the for loop, choose a
random name from colleges,
append it to rankings
and then remove it from colleges.
WARNING:
you will need to pay close attention to
the range for your random number, since
it will depend on the current length of
the list colleges.
- Finally, display your college
ranking as a two column table, with the
ranking number on the left and the
corresponding college name on the
right. I will award a special
prize for anyone whose rankings happen
to randomly put St. Lawrence in the top
three when I run your program!
- Now we will advance a school in the
rankings. Ask the user to enter the name
of a school. If the name entered is
actually in rankings
then delete it from its current position
and reinsert it one position earlier.
Then redisplay the ranking table to
reflect the change in status of this
school. (You can just cut and paste
previous code.)
|
|
|