Lists exercises 2

posted by: Ms. Martin 4 May 2010 No Comment

Please take your time going over the list tutorial and the first set of exercises.  Once you are comfortable with those, take a look at the advanced list examples and move on to these.

As usual, please jump around as you wish.

Activity 1: Magic Eight Ball (Jason’s idea!!)

Create a program that prompts the user for a question then gives a magic eight ball answer.  Your program should randomly pick an answer from a list of choices.  Feel free to use the standard answers listed on the Wikipedia article or to make up your own creative ones.  Your program should keep asking the user for questions until he or she types “exit.”

This is one that can easily be expanded.  You could use Turtle Graphics to show a visual representation of the Eight Ball.  You could  report how many positive and negative answers were given.

Activity 2: Temperature Conversion

Remember writing a temperature conversion function?  Either dig it out or write it again.  Your program should start with a list of temperatures in Celsius, should convert them to Fahrenheit and store the results in a second list then print out both lists.

Activity 3: Multiplication table

Prompt the user for a number.  Use the range function to print out a multiplication table for numbers between 0 and the desired bound.

Activity 4: Dice statistics

Write a program to roll a die 200 times then report how many 1s, 2s, 3s, etc were rolled.  Draw a histogram of the data using Turtle Graphics.

Activity 5: Cards

Write as short of a program as possible to generate a list of all 52 cards in a standard card deck.  You can choose how to represent cards.  I recommend doing something like building strings that first have the rank then the suit.  For example, the list might start with ["1club", "2club", "3club", ... "kingclub"...]  Then, shuffle the resulting deck and print it out.

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>