1.8. High/Low Guess My Number Game#
1.8.1. Instructions#
Write pseudocode and Python function program to interactively play the following game:
Generate a random integer number between 0 and 100.
Ask the player to guess a number. Capture their input from the keyboard.
Check if the number is valid (between 0 and 100, integer). If not, warn the player and goto Step 2.
If the player’s guess is correct, they win. Print out “Congratulations” and tell them how many guesses it took. Only count valid guesses. Terminate the program.
If the guess is too low, print “Guess is too low.” and goto Step 2.
If the guess is too high, print “Guess is too high.” and goto Step 2.
First write the pseudocode and then implement as a function in Python. Test your program at least 2 times.
1.8.2. Your Function#
# import libraries
import numpy as np
# function to accept guess from user and determine if guess matches secret
# number between 0 and 100
def guessing_game(rand_num=None):
''' Play the guess my number interactively with keyboard input
Argument:
rand_num: the random (secret) number. If None (default), the program generates
a random integer between 0 and 100.
Returns:
Nothing
Other:
Asks user for interactive keyboard input that are integers
'''
# Add your solution here
1.8.3. Test 1#
Test 1: No input. The function will automatically generate a secret number.
# Add your solution here
1.8.4. Test 2#
Test 2: What happens if we supply an out-of-bounds (invalid) secret number? Try -2.
# Add your solution here