import random
def guessGame(a, b, num_random):
guess = int(input(f"Guess a number between {a} to {b}:\n"))
nguess = 1
while guess != num_random:
if guess < num_random:
guess=int(input("Enter bigger!\n"))
nguess += 1
else:
guess=int(input("Enter less!\n"))
nguess += 1
print(f"You guess the number in {nguess} attempt\n")
return nguess
if __name__ == "__main__":
a = int(input("Enter the value A"))
b = int(input("Enter the value B"))
num_random1 = random.randint(a, b)
print("Player 1's is turn")
g1 = guessGame(a, b, num_random1)
print("Player 2's is turn")
num_random2 = random.randint(a, b)
g2 = guessGame(a, b, num_random2)
if g1 < g2:
print("Player 1 win!\n")
elif g1 > g2:
print("Player 2 win!\n")
else:
print("Tie!")
print(f"Player 1 number is {num_random1} and Player 2 number is {num_random2} !\n")
No comments:
Post a Comment