Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python coding Modify the guessing-game program so that the user thinks of a number that the computer must guess. The computer must make no more

Python coding

Modify the guessing-game program so that the user thinks of a number that the computer must guess.

  • The computer must make no more than the minimum number of guesses, and it must prevent the user from cheating by entering misleading hints.
  • Use I'm out of guesses, and you cheated and Hooray, I've got it in X tries as your final output.

(Hint: Use the math.log function to compute the minimum number of guesses needed after the lower and upper bounds are entered.)

Below are two test runs of the program:

Enter the smaller number: 0 Enter the larger number: 10 0 10 Your number is 5 Enter =, <, or >: < 0 4 Your number is 2 Enter =, <, or >: > 3 4 Your number is 3 Enter =, <, or >: = Hooray, I've got it in 3 tries!
Enter the smaller number: 0 Enter the larger number: 50 0 50 Your number is 25 Enter =, <, or >: < 0 24 Your number is 12 Enter =, <, or >: < 0 11 Your number is 5 Enter =, <, or >: < 0 4 Your number is 2 Enter =, <, or >: < 0 1 Your number is 0 Enter =, <, or >: > 1 1 Your number is 1 Enter =, <, or >: > I'm out of guesses, and you cheated!

Starter code:

# Modify the code below:

import random

smaller = int(input("Enter the smaller number: "))

larger = int(input("Enter the larger number: "))

myNumber = random.randint(smaller, larger)

count = 0

while True:

count += 1

userNumber = int(input("Enter your guess: "))

if userNumber < myNumber:

print("Too small")

elif userNumber > myNumber:

print("Too large")

else:

print("You've got it in", count, "tries!")

break

Some iputs that need to work:

0 10 < > =

0 25 < > > > =

0 50 < < < < > >

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_2

Step: 3

blur-text-image_3

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

6. Vanguard

Answered: 1 week ago