اين الخطأ
3 إعجابات
سلام عليكم ورحمت الله وبركاته
حضرتك نسيت تسدعي مكتبة random و ايضا هناك اخطاء في الكود الخاص بك إليك الكود الخاص بي لتقارن كودك مع كودي و حاول تستكشف الأخطاء كودك و تصليحها و حاول ان تتعلم من الأخطاء
import random
choise = int(input("Welcome to the coin toss game \n1. you have chosen random.randint() \n2. you have chosen random.random()\nEnter your choice 1 oг 2..."))
if choise == 1:
str_random = random.randint(0,1)
if str_random == 1:
computer_guess = "heads"
else:
computer_guess="tails"
elif choise == 2:
str_random = random.random()
if str_random >= 0.5:
computer_guess ="heads"
else:
computer_guess="tails"
else:
print("Invalid choice")
print("Please enter 1 or 2")
User_choose = input("Enter your choice of (Heads) or (Tails): ").lower()
if User_choose == computer_guess:
print("Well done, you won.")
else:
print("Sorry you lost, you can try again")
3 إعجابات
انا استدعيت مكتبة random بس انا مصورة من السطر السادس
ممكن تكتبلي وين الخطأ لاني ما لاحظته
إعجاب واحد (1)
الخطء في lower نسيتي تكتبي الاقواس في السطر الاول و كتبتيها في السطر التاني مرة واحة تكفي
User_choose = input("Enter your choice of (Heads) or (Tails): ").lower()
if User_choose == computer_guess:
إعجابَين (2)
الخطأ في نهاية السطر 22
()lower لازم يكون فيها القوسين
إعجابَين (2)
ممكن تنسخ الكود كله عشان اعرف أحدد الأخطاء كلها و اقولك عليه ؟