C2 – Guess My Number 100

This is a programming exercise. You must write a Python script that allows a user four tries to guess a random number between 1 and 100. After each incorrect guess, one or more hints will be output.

Requirements

Create a Python script named guess100.py that runs the "Guess My Number 100" game. The game allows a user four tries to guess a random number between 1 and 100. After the first try, the game will always output whether the user's guess is greater than or less than the answer. On the second incorrect try, the game will output whether the answer is even or odd. On the third incorrect try, the game will output whether the answer is divisible by 3 or 5. After four incorrect tries, the user loses the game.

To complete this program, you must use variables, conditionals, and a while loop. You must also create and use the following functions:

  • print_greater_or_lesser(guess, target)
    Prints whether the guess is greater than or less than the target value. Does not print anything if the guess and target value are equal.
  • print_even_or_odd(value)
    Prints whether the specified value is even or odd.
  • print_divisible_by(value, divisor)
    Prints whether the value is divisible by the specified divisor.

See the examples below for the output your program should generate.

Example

Here is an example where the user wins on the first guess:

(click image to enlarge)

Here is an example where the user loses:

(click image to enlarge)

Hints

When you are writing this program, you are going to want to know the number ahead of time for debugging purposes. The simplest way to do this is to print the answer. Just make sure you comment out this line when you are done!

Submission

When complete, run your script for the instructor. (For testing purposes, please print the answer at the start of the script.)

If you do not finish by the end of the class, you may email the script to the instructor. Please include the following subject line for your email:

MSAN 501 Day 1 – Guess My Number 100

Make sure you include your full name in the email body.