import random
print("""Welcome to the Coin Guessing Game! \nchoose a method to toss the Coin: \n 1. Using random.random() \n 2.Using random.randint() \n""")
num = int(input("enter 1 or 2: \n"))
if num == 1:
if random.random() >= 0.5:
computer_result = "heads"
else: computer_result = "tails"
elif num == 2:
if random.randint(0,1) == 0:
computer_result = "heads"
else: computer_result = "tails"
else:
print("Invalid choice. please select either 1 or 2,")
exit()
user_num = input("enter your guess(heads or tails):")
if user_num.lower() == computer_result.lower():
print("congratulations! you win")
else:
print("sorry, you lost!")
print(f"the computer's coin toss result was: {computer_result}")
اذا دخل المستخدم احرف او رموز بدل الارقام يحصل خطا كيف اصحح ال ايرورر هذا ؟