01 Prove : Assignment
Objective
Demonstrate knowledge of variables, conditionals, and loops in Python.
Overview
Write a Python 3 program that randomly selects a number from 1-100, and then prompts the user for guesses. After each incorrect guess, the program helps the user by directing them to guess higher or lower. When the user guesses the correct number, the program will display the number of guesses the user made and ask them if they would like to play again.
Sample Output
Welcome to the number guessing game!
Enter random seed: cat
Please enter a guess: 42
Lower
Please enter a guess: 25
Higher
Please enter a guess: 30
Higher
Please enter a guess: 35
Lower
Please enter a guess: 33
Lower
Please enter a guess: 32
Lower
Please enter a guess: 31
Congratulations. You guessed it!
It took you 7 guesses.
Would you like to play again (yes/no)? yes
Please enter a guess: 75
Higher
Please enter a guess: 80
Higher
Please enter a guess: 90
Lower
Please enter a guess: 85
Lower
Please enter a guess: 82
Congratulations. You guessed it!
It took you 5 guesses.
Would you like to play again (yes/no)? no
Thank you. Goodbye.
Hint: Working with Random Numbers
Python has a module for easily working with random numbers. You can import randint from the random module, and then call that function to return a random number from a min to max value:
from random import randint
num = randint(low, high)
In order for the testBed to predict what your random numbers will be, you will need to "seed" it with a certain value to begin. This can be done by importing random and then calling the random.seed() function with a value. This only needs to be called once at the beginning of your program, not every time a random number is generated.
Putting it all together would like something like this:
import random
from random import randint
# ... other stuff here ...
random.seed(the_seed_value)
# ... possibly more stuff here ...
num = randint(1, 50)
# the variable num now contains a random number from 1 to 50
Automatic Grading Script (TestBed)
An auto-grading testbed script is provided for you to help evaluate your program. This same testbed script will be used as part of the grading of your program. However, unlike the Checkpoint programs, your code will also be evaluated for style and overall design / implementation.
The TestBed script can be run as follows:
testBed cs241/assign01 myAssign01.py
Submission
Submit your program by logging into the CS Department Linux system, and running the submit command with your filename. Example (assuming my file is named "myAssign01.py":
submit myAssign01.py
You should then select the appropriate course (CS 241), instructor, and assignment (assign01) from the list.
Assessment and Grading
For your information, the instructor will use these assessment guidelines to evaluate your assignment. Feel free to refer to this to understand the expectations of this submission.