[Tutor] While loop exercise

Andrei project5 at redrival.net
Sun May 22 19:33:08 CEST 2005


. , <administrata <at> hotmail.com> writes:

> I just finished the chapter which includes while loop, if-else-elif 
> structure and randrange().
> 
> Can anyone suggest me 3 exercises to remind of the chapter?

The standard exercise which includes all three would be a number guessing game
where the computer picks a number and the user guesses it (the opposite is also
possible, but then randrange is not useful). A while loop is standard in *any*
program that can be executed more than once. E.g. asking someone for a string is
a single line of code, but asking for an unlimited number of strings directly
requires a while loop.

> Looking forward to writing some programs!

At this stage there aren't many really useful application you can make, but you
should use your fantasy. Pick a subject you know something about and make a
simple application for it. I think there are lots of suitable subjects in maths,
physics and children's games, but you can find suitable subjects in lots of
other fields too.

Other possible small programs using while and if (randrange is a bit exotic and
not that useful):
- let the user input names and dates of birth. Calculate membership fee to a
club based on whether the person is a child, an adult or a senior citizen.
- a quadradic formula solver (would have to check whether the determinant < 0)
- a hangman game
- a free fall calculator (given an object that is dropped from a certain height,
calculate a table with its position as a function of time)
- a quiz program about some topic you like (could even use randrange in this one
to pick questions)
- a program which combines some of the programs above - e.g. allow the user to
play either number guessing or hangman.
- a hotel booking application which allows making reservations for one or
2-person rooms and applies a discount if the reservation is on a day between
monday and thursday. 

Yours,

Andrei



More information about the Tutor mailing list