import random

def game():
  target = random.randint(1, 100)
  guess = None
  attempts = 0
  
  while guess != target:
    guess = int(input("Guess a number between 1 and 100: "))
    attempts += 1
    if guess < target:
      print("Too low, try again.")
    elif guess > target:
      print("Too high, try again.")
    else:
      print(f"You got it in {attempts} attempts!")

if __name__ == '__main__':
  print("Welcome to the Number Guessing Game!")
  game()
Welcome to the Number Guessing Game!
Too low, try again.
import random
import math
# Taking Inputs
lower = int(input("Enter Lower bound:- "))
 
# Taking Inputs
upper = int(input("Enter Upper bound:- "))
 
# generating random number between
# the lower and upper
x = random.randint(lower, upper)
print("\n\tYou've only ",
       round(math.log(upper - lower + 1, 2)),
      " chances to guess the integer!\n")
 
# Initializing the number of guesses.
count = 0
 
# for calculation of minimum number of
# guesses depends upon range
while count < math.log(upper - lower + 1, 2):
    count += 1
 
    # taking guessing number as input
    guess = int(input("Guess a number:- "))
 
    # Condition 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,
# shows this output.
if count >= math.log(upper - lower + 1, 2):
    print("\nThe number is %d" % x)
    print("\tBetter Luck Next time!")
 
# Better to use This source Code on pycharm!
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/chrisalbertson/Downloads/The-Grand-Universe/_notebooks/2023-02-6-NumberGame.ipynb Cell 2 in <cell line: 7>()
      <a href='vscode-notebook-cell:/Users/chrisalbertson/Downloads/The-Grand-Universe/_notebooks/2023-02-6-NumberGame.ipynb#W1sZmlsZQ%3D%3D?line=3'>4</a> lower = int(input("Enter Lower bound:- "))
      <a href='vscode-notebook-cell:/Users/chrisalbertson/Downloads/The-Grand-Universe/_notebooks/2023-02-6-NumberGame.ipynb#W1sZmlsZQ%3D%3D?line=5'>6</a> # Taking Inputs
----> <a href='vscode-notebook-cell:/Users/chrisalbertson/Downloads/The-Grand-Universe/_notebooks/2023-02-6-NumberGame.ipynb#W1sZmlsZQ%3D%3D?line=6'>7</a> upper = int(input("Enter Upper bound:- "))
      <a href='vscode-notebook-cell:/Users/chrisalbertson/Downloads/The-Grand-Universe/_notebooks/2023-02-6-NumberGame.ipynb#W1sZmlsZQ%3D%3D?line=8'>9</a> # generating random number between
     <a href='vscode-notebook-cell:/Users/chrisalbertson/Downloads/The-Grand-Universe/_notebooks/2023-02-6-NumberGame.ipynb#W1sZmlsZQ%3D%3D?line=9'>10</a> # the lower and upper
     <a href='vscode-notebook-cell:/Users/chrisalbertson/Downloads/The-Grand-Universe/_notebooks/2023-02-6-NumberGame.ipynb#W1sZmlsZQ%3D%3D?line=10'>11</a> x = random.randint(lower, upper)

ValueError: invalid literal for int() with base 10: 'Upper bound'