I need help finishing a coding project for a computer science class, I don't know how to start it
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!")
Comments
Leave a comment