import random
print(“welcom to the coin guessing game! \nchoose amethod to toss the coin: \n1-using random. random()\n2-using random.randint() “)
number=int(input(” enter your choice (1 or 2): \n”))
if number==1:
my_random=random.random()
if my_random>=0.5:
rck=“heads”
else:
rck=“tails”
elif number==2:
my_random=random. randint(0,1)
if my_random==0:
rck=“heads”
else:
rck=“tails”
else:
print(“invalid choice (1 or 2)”)
choose=input("enter your guess (hrads or tails) “)
if choose.lower()==rck.lower():
print(” congratulations “)
else:
print(“invalid choice (heads or tails)”)
print(f” the computer {rck} ")
ايه الغلط في الكود كل ما اجرب اكتب رقم غير 1 او 2 يقولي غلط ويكمل عادي المفروض يقف لو المستخدم كتب حاجه غلط
import random
print("welcom to the coin guessing game! \nchoose amethod to toss the coin: \n1-using random. random()\n2-using random.randint() ")
number=int(input(" enter your choice (1 or 2): \n"))
if number==1:
my_random=random. randint(0,1)
if my_random>=0.5:
rck="heads"
else:
rck="tails"
elif number==2:
my_random=random.random()
if my_random==0:
rck="heads"
else:
rck="tails"
else:
print("invalid choice (1 or 2)")
choose=input("enter your guess (hrads or tails) ")
if choose.lower()==rck.lower():
print(" congratulations ")
else:
print("invalid choice (heads or tails)")
print(f" the computer {rck} ")
كان random.random متبدل مع random.randint
و بالنسبة للمشكلة بتاعت أن الكود بيتكمل فممكن ناخد الجزء الاخير نعمله نسخ تحت كل خيار
زى ده
import random
print("welcom to the coin guessing game! \nchoose amethod to toss the coin: \n1-using random. random()\n2-using random.randint() ")
number=int(input(" enter your choice (1 or 2): \n"))
if number==1:
my_random=random. randint(0,1)
if my_random>=0.5:
rck="heads"
else:
rck="tails"
choose=input("enter your guess (heads or tails) ")
if choose.lower()==rck.lower():
print(" congratulations ")
elif choose.lower()!=rck.lower():
print ("you lost,Game over")
else:
print("invalid choice (heads or tails)")
print(f" the computer choice {rck} ")
elif number==2:
my_random=random.random()
if my_random==0:
rck="heads"
else:
rck="tails"
choose=input("enter your guess (heads or tails) ")
if choose.lower()==rck.lower():
print(" congratulations ")
elif choose.lower()!=rck.lower():
print ("you lost,Game over")
else:
print("invalid choice (heads or tails)")
print(f" the computer choice {rck} ")
else:
print("invalid choice (1 or 2)")