#Mini Project 1:
#Random no Guessing Game Challenge
#After every accepting no, program shows msg higher or lower
#Also count the total no of attempts.
#if match found then print 'congratulation!' message
import random
limit = int(input("Enter upper bound / max Limit"))
no = random.randint(1,limit)
guess = int(input(f"Enter Your guess number between 1 and {limit}"))
cnt=1;
while no!=guess:
if guess < no:
print("You need to guess higher. Try Again")
else:
print("You need to guess Lower. Try Again")
guess = int(input(f"Enter Your guess number between 1 and {limit}"))
cnt+=1
print("Congratulation!! Finally you guess the number")
print("No of Attempts : ",cnt)
Output:
Enter upper bound / max Limit500
Enter Your guess number between 1 and 500250
You need to guess Lower. Try Again
Enter Your guess number between 1 and 500100
You need to guess Lower. Try Again
Enter Your guess number between 1 and 50050
You need to guess higher. Try Again
Enter Your guess number between 1 and 50075
You need to guess Lower. Try Again
Enter Your guess number between 1 and 50060
You need to guess higher. Try Again
Enter Your guess number between 1 and 50065
You need to guess higher. Try Again
Enter Your guess number between 1 and 50070
You need to guess Lower. Try Again
Enter Your guess number between 1 and 50069
Congratulation!! Finally you guess the number
No of Attempts : 8