import random
print("Welcome to the Coin Guessing Game!")
print ("Choose a method to toss the coin: \n 1. Using random.random() \n 2. Using random.randint()")
choice = input("Enter your choice (1 or 2): \n ")
guess = input("Enter your Guess (Heads or Tails): \n ").lower()
if guess not in ["tails", "heads"]:
print("Invalid choice. Please select either Heads or Tails")
else:
if choice == "1":
res = "heads" if random.randint(0,1) ==1 else "tails"
if res == guess:
print("Congratulations! You won!")
print(f"The computer's coin toss result was: {res}")
elif res != guess:
print("Sorry, You lost!")
print(f"The computer's coin toss result was: {res}")
elif choice == "2":
res = "heads" if random.random() >=0.5 else "tails"
if res == guess:
print("Congratulations! You won!")
print(f"The computer's coin toss result was: {res}")
elif res != guess:
print("Sorry, You lost!")
print(f"The computer's coin toss result was: {res}")
else:
print("Invalid choice. Please select either 1 or 2")
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)