Answer to Question #254520 in Python for cait

Question #254520

I need help finishing a coding project for a computer science class, I don't know how to start it


1
Expert's answer
2021-10-21T05:21:20-0400
import random


import math


low = int(input("Enter Lower number:- "))
 



up = int(input("Enter Upper number:- "))
 
# generating random number between the given numbers



x = random.randint(low, up)


print("\n\tYou've only ", 


       round(math.log(up - low + 1, 2)),


      " chances to guess the integer!\n")
 
# Initializing the numberof times


count = 0
 
# for calculation of minimum guess


while count < math.log(up - low + 1, 2):


    count += 1
 


    # taking guessing number as input


    guess = int(input("Guess a number:- "))
    
    # testing


    if x == guess:


        print("Congratulations you did it in ",


              count, " try")


        # Once guessed, loop will break


        break


    elif x > guess:


        print("You guessed too small!")


    elif x < guess:


        print("You Guessed too high!")
 
# If Guessing is more than required guesses
 


if count >= math.log(up - low + 1, 2):


    print("\nThe number is %d" % x)


    print("\tBetter Luck Next time!")
 
 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS