import random
print("welcom to the coin Guessing Game")
print("choose a method to toss the coin:")
print("1. using random.random()")
print("2. using random.randint()")
choice = input("Enter your choie (1 or 2): ")
#random.randint
if choice=="1":
random_1 = random.random()
if random_1>=0.5:
computer_result="tails"
else:
computer_result="heads"
elif choice=="2":
if random.randint(0 , 1) == 0:
computer_result="tails"
else:
computer_result="heads"
else:
print("invalid choice :please select 1 or 2")
user_choice= input("Enter your guess (Heads or atails) ")
if user_choice.lower==computer_result.lower():
print("congratulation . you won")
else:
print("sorry you lost")
السؤال
Joseph Joseph
import random print("welcom to the coin Guessing Game") print("choose a method to toss the coin:") print("1. using random.random()") print("2. using random.randint()") choice = input("Enter your choie (1 or 2): ") #random.randint if choice=="1": random_1 = random.random() if random_1>=0.5: computer_result="tails" else: computer_result="heads" elif choice=="2": if random.randint(0 , 1) == 0: computer_result="tails" else: computer_result="heads" else: print("invalid choice :please select 1 or 2") user_choice= input("Enter your guess (Heads or atails) ") if user_choice.lower==computer_result.lower(): print("congratulation . you won") else: print("sorry you lost")
6 أجوبة على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.