In this exercise you will practice
This is an individual assignment.
Collaboration at a reasonable level will not result in substantially similar code. Students may only collaborate with fellow students currently taking this course, the TA’s and the lecturer. Collaboration means talking through problems, assisting with debugging, explaining a concept, etc. You should not exchange code or write code for others.
Notes:
You like guessing secret numbers and your friends won’t play with you.
Write a program in a file called guess_number.py
that randomly chooses a secret number from 1 to 10, inclusive, and asks the user to guess the number.
As long as the user guesses incorrectly or doesn’t enter “quit” the program should keep asking the user to keep guessing.
If the user guesses the correct number then, before exiting, print “Yay! You guessed it.
It was N.” where N is the randomly chosen secret number.
If the user guesses incorrectly print “Higher” or “Lower” depending on whether the secret number is higher or lower than the guess.
If the user quits before guessing correctly print “Lame. It was N.” where N is the randomly chosen secret number.
For this assignment you may assume that you get valid input from the user.
Use the random
module to generate a random number.
Use the built-in input
function to get user input.
input
? What do you need to do with that value to compare it to the random secret number?Submit your guess_number.py
file on Canvas as an attachment. When you’re ready, double-check that you have submitted and not just saved a draft.
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.