Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will add to the program you created last week. This week you will add a list to keep track of all the numbers guessed

You will add to the program you created last week. This week you will add a list to keep track of all the numbers guessed and modularize your code. Be sure to import random at the beginning of your code and use a comment block explaining what your program does. Please use the following code to ADD to it (You picked the following number:) This is should be displayed after (You guessed it in ___ attempts)

import random

import sys

print('Welcome to my Guess the number program!')

print()

while (True):

print('1. You guess the number')

print('2. You type a number and see if the computer can guess it')

print('3. Exit')

print()

option=int(input('What is your choice:'))

print()

if(option ==1):

number=random.randint(1, 10)

count=0

while (True):

try:

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

print()

count = count + 1

if guess < 0:

continue

elif guess < number:

print('Too low')

print()

elif guess > number:

print('Too high')

print()

elif guess == number:

break

except:

print('Numbers only')

print()

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

print()

if(option ==2):

print()

number=int(input('Please enter a number between 1 and 10 for the computer to guess:'))

print()

count=1

while True :

randomval=random.randint(1, 10)

if (number

print('The computer guessed',randomval,'which is too low')

print()

count=count+1

elif (number>randomval):

print('The computer guessed',randomval,'which is too high')

print()

count=count+1

elif (number==randomval):

break

print('The computer guessed it! It took',count,'attempts.')

print()

if(option==3):

print('Thank you for playing the guess the number game!')

sys.exit(0)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Assessing marketing information needs

Answered: 1 week ago

Question

Identify the nine clusters in the analytics ecosystem.

Answered: 1 week ago