Reference no: EM132355340
Question
You will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number. In addition, you will add a menu system. 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 6
#Name:
#Date:
#Menu system displays - ask user if they want to guess a number, have computer guess a number, or exit
#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
#ask user to enter a number, computer randomly guesses
Display "Welcome to my Guess the number program!"
while true
Display "1. You guess the number"
Display "2. You type number and see if the computer can guess it"
Display "3. Exit"
Get option
if(option ==1)
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"
if(option ==2)
Get number from user
count=1
while True
Get randomval from computer
if (number<randomval)
Display "Too low"
count=count+1
else if (number>randomval)
Display "Too high"
count=count+1
else if (number==randomval)
Display "The computer guessed it in "+ count + " attempts. The number was "+randomval
else
break
When you run the program you should see something like the following:
Welcome to my Guess the number program!
You guess the number
You type number and see if the computer can guess it
Exit
What is your choice: 1
Please guess a number between 1 and 10: 8
Too high
Please guess a number between 1 and 10: 7
You guessed it! It took you 2 attempts
You guess the number
You type number and see if the computer can guess it
Exit
What is your choice: 2
Please enter a number between 1 and 10 for the computer to guess: 5
The computer guessed 7 which is too high
The computer guessed 2 which is too low
The computer guessed 9 which is too high
The computer guessed 8 which is too high
The computer guessed 8 which is too high
The computer guessed 1 which is too low
The computer guessed 3 which is too low
The computer guessed 4 which is too low
The computer guessed 2 which is too low
The computer guessed 8 which is too high
The computer guessed 3 which is too low
The computer guessed 1 which is too low
The computer guessed 4 which is too low
The computer guessed 7 which is too high
The computer guessed 1 which is too low
The computer guessed 7 which is too high
The computer guessed 1 which is too low
The computer guessed 4 which is too low
The computer guessed 4 which is too low
The computer guessed it! It took 20 attempts
You guess the number
You type a number and see if the computer can guess it
Exit
What is your choice: 3