You will add to the program you created last week. This week you will add input validation and a count to show how many guesses the user took before getting the correct number
Need help with this assignment?Get an original answer from a qualified tutor — from $10/page.
Get it written →You will add to the program you created last week. This week you will add input validation and a count to show how many guesses the user took before getting the correct number. The pseudocode is below. Be sure to import random at the beginning of your code and use a comment block explaining what your program does
#Guess the number week 5
#Name:
#Date:
#Random number, loop while true
#ask user for number. Check to see if the value is a number between 1 and 10
#if number is too high or too low, tell user, if they guessed it break out of loop
Display “Welcome to my Guess the number program!”
random mynumber
count=1
while True
try
Display “Guess a number between 1 and 10”
Get guess
while guess<1 or guess>10
Display “Guess a number between 1 and 10”
Get guess
except
Display “numbers only”
continue
if (guess<mynumber)
Display “Too low”
count=count+1
else if (guess>mynumber)
Display “Too high”
count=count+1
else if (guess==mynumber)
Display “You guessed it in “+ count + ” attempts”
When you run the program the result should look like the following:
Welcome to my Guess the number program!
Please guess a number between 1 and 10: a
Numbers only!
Please guess a number between 1 and 10: -3
Please guess a number between 1 and 10: 4
Too low
Please guess a number between 1 and 10: 5
Too low
Please guess a number between 1 and 10: 6
You guessed it! It took you 3 attempts
Get a plagiarism-free answer to this question
Send us your instructions and we’ll match you with the best writer in your subject.
- 100% human-written, zero AI
- Turnitin report included
- Confidential — we never share your data
- Free revisions & refunds