First Summer 2006


Homework Six: Looping in Python programs (mostly related to chapters 3, 4, 5 and 6 in the Python text).
Due date
Monday May 29, 11:59pm
Late policy
Please turn everything on time, late solutions will not be accepted.

We are also planning a help (review) session on Monday or Tuesday night.

Work policy
Working in groups is encouraged but please turn in your own version of the assignment.

Also, please make sure you

with the Computer Science Department's Statement on Academic Integrity before turning in your assignment.

Task
Write programs that solve the following problems:

  1. (Palindrome) A palindrome is a string that is spelled the same way backward and forward. For example: 'mom', 'dad', 'radar', '747', and 'madam im adam' are all examples of palindromes. Two more examples are 'able was i ere i saw elba' and 'a man, a plan, a canal: panama'. Write a program that lets the user type a word or phrase and then determines whether the string is a palindrome (ignore the spaces and other diacritical marks, commas etc.).
  2. (Guess the number) Write a program that starts with the computer picking a random number between 1 and 100. The user then tries to guess the number in as few attempts as possible. After each guess the computer gives the user feedback, whether the guess is too low, too high or just right. The game ends when the user guesses the random number.
  3. (Hangman game) Write a program to play the hangman game with the user. The computer chooses a random word from a list of words and the user tries to guess it one letter at a time. Here's how the game works. After the computer picks a secret word it then prints one asterisk for each letter in the word: * * * *. The user then guesses at the letters in the word. For every correct guess, an asterisk is replaced by a letter: * e * * *. Every incorrect guess is counted. If the user does not guess the word with less than six mistaken guesses the program ends, the user loses. Otherwise the user wins.
  4. (Guess the jumbled word) The computer picks a random word from a list of guesses. It then randomly rearranges the letters in the word and shows the word to the user. The user has to guess the word with less than six bad guesses.
  5. (Min and max) Write a program that lets the user input a sequence of integers terminated by the string 'done'. The program should then report the largest and smallest values that were entered.
  6. (Fire Extinguisher) Suppose you determine that the fire extinguisher in your kitchen loses x percent of its foam every day. How long before it drops below a certain threshold (y percent), at which point it is no longer serviceable? Write a program that lets the user input the x and y and then reports how many weeks the fire extinguisher will last.

Grading
Feedback will be provided within a week, grades will be posted on-line.