Guess The Number Game - You vs. Your Friend
Guess a Random Number Game
import random
print("\nWelcome to the Guess a random number Game!")
print("Its a 2 player game.")
print("The Winner is the one with the lowest attempts.\n")
lower_limit = int(input("Plz choose the lower limit? "))
upper_limit = int(input("Plz choose the upper limit? "))
winner = []
for i in range(2):
random_number = random.randint(lower_limit, upper_limit)
print(f"\nIts player {i+1} turn:")
guess_number = ""
attempts = 0
while guess_number != random_number:
attempts += 1
guess_number = int(input(f"Player {i+1}, Plz guess the number between {lower_limit} and {upper_limit}: "))
if guess_number < random_number:
print("Plz choose higher number")
elif guess_number > random_number:
print("Plz choose lower number")
else:
print(f"Player {i+1}, You correctly guessed the number (which was {random_number}) in {attempts} attempt(s).")
winner.append(attempts)
if winner[0] < winner[1]:
print("\nPlayer 1 is the winner.\n")
elif winner[0] > winner[1]:
print("\nPlayer 2 is the winner.\n")
else:
print("Game Draw!")
Comments
Post a Comment
Write something to CodeWithAbdur!