Momentum logo
Team 10 Classroom

Working with modules

Step 1

Write a simple number guessing game. Your game should import the random module to generate a random integer between 1 and 20. When the program runs, it should prompt the user for a guess and then tell them if their guess was too high, too low, or correct.

Hint: There is an example of how to accept user input on the command line in Jupyter notebook 03 - Input and Output.

Step 2

Modify your game so that it tells the user how many tries it took them to guess the right number.

Step 3

Limit the number of tries a user has to guess the number correctly. If the user doesn’t guess it in the number of tries you’ve limited them to, they lose.

🔡 Variation

If you get all this working, create another version of the game that asks the user to guess a letter of the alphabet, and gives hints based on the alphabetical order of the player’s guess.

Your user should be able to choose whether they want to play number guess or letter guess when the game starts.