**
Fill This Form To Receive Instant Help**

Homework answers / question archive / print('Welcome to my Guess the number program!') count = int(0) #Generate a random number number = random

count = int(0)

#Generate a random number

number = random.randint(1, 10)

while (True):

try:

#prompt the user to guess

guess=input('Guess a number between 1 and 10: ')

guess = int(guess)

#count number of attempts

count = count + 1

#if guess is less than zero continue to guess again

if guess < 0:

continue

#if the number is less than the number print the message

elif guess < number:

print('Too low')

#if the number is greater than the number print the message

elif guess > number:

print('Too high')

elif guess == number:

break

except:

#if a non number is guessed print the message

print('Numbers only!')

#otherwise, display the message and end the game

print('You guessed it! It took you', count, 'attempts')

The Week 6 portion of your Course Project is due this week. Please refer to the Course Project Overview in the Introduction and Resources module for full details.

Guess the 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

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

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!

Be sure to submit your assignment.