You will add to the program you created last week. This week 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.
You will add to the program you created last week. This week 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 a 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 a 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 a 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
Thank you for playing the guess the number game!
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.
