PDA

View Full Version : Python Challenge 5: Lists Part 2



yuvlevental
August 16th, 2007, 11:00 PM
First, the program I will refer to:

print “List of First Five Greek Letters”
greek_letters = [’Beta’, ‘Alpha’, ‘Gamma’, ‘Delta’, ‘Epsilon’]
print “Third value in list is: “, greek_letters[2]
greek_letters[2] = 3
print “Value has been changed. It is now: “, greek_letters[2]
print “Length of list is: “, len(greek_letters)
del greek_letters[2]
print “Third letter has been deleted. Length is now: “, len(greek_letters)
if “Alpha” in greek_letters:
                        print “Alpha is in the list at the moment.”
else:
                      print “Alpha is not in the list at the moment.”
print “The current list: “, greek_letters
print ‘Alpha is in position’, greek_letters.index(’Alpha’) + 1
greek_letters.sort()
“List has been sorted alphabetically.”
print “New list: “, greek_letters
print ‘Alpha is in position’, greek_letters.index(’Alpha’) + 1
greek_letters.remove(”Beta”)
print”Beta has been removed.”, greek_letters

The challenge: In the program, the list, variables, ect. is determined. The challenge is to make a program where there a list, which is initially blank, and you can add, remove, print, sort, ect. items to the list. Taken from my lesson here (http://my-python-blog.freehostia.com/?p=19). Email the answer to yuval [dot] imperius [at] gmail [dot] com. You will be credited on the forums (http://my-python-blog.freehostia.com/forum/) and get 40 credits.

Jessehk
August 16th, 2007, 11:55 PM
The challenge: In the program, the list, variables, ect. is determined. The challenge is to make a program where there a list, which is initially blank, and you can add, remove, print, sort, ect. items to the list. Taken from my lesson here (http://my-python-blog.freehostia.com/?p=19). Email the answer to yuval [dot] imperius [at] gmail [dot] com. You will be credited on the forums (http://my-python-blog.freehostia.com/forum/) and get 40 credits.

So the challenge is to use the list class in a program? Your posts continue to confuse me. :confused:

yuvlevental
August 17th, 2007, 12:09 AM
Pretty much. In the program I'm looking for, there are several options what you can do with a pre-created list that is initially blank. The user can add and remove items, print out the list, order the list alphabetically, ect.

smartbei
August 17th, 2007, 08:52 PM
So nearly the whole challenge lies in interpreting user input. Do you plan on increasing the difficulty for your challenges?

On a side note, please use [ code][ /code] tags for code.

gnuman
August 18th, 2007, 03:26 AM
I think the point is to have the challenges build up in complexity, which is a good idea. For instance, if students are learning, say, dictionaries, you could start with simple challenges like this:

1. Create a small program in which the user can give a key and have the value printed.

2. Create a small program in which the user can print a table of key/value pairs sorted by keys.

3.....etc

Now after a few of these you can then hit them with something like this:

8. Now, create an employee/salary database program that will allow the user to:
--Enter new employees and salaries
--Edit an employees salary
--Delete an employee
--Print a table sorted alphabetically
--Print a formatted table sorted by salary
--save/load the database to a file
--interact with the program in a simple menu system