`import random
print("Welcome to the Rock, Paper, Scissors game:")
input("Press Enter to continue or type (help) for the rules:")
print(f"************** RULES ***************\n 1) You choose and the computer chooses\n 2) Rock smashes Scissors ==> Rock wins \n 3) Scissors cut Paper ==> Scissors win \n 4) Paper covers Rock ==> Paper wins")
user_choice = input("Please enter your choice (Rock, Scissors, Paper): ").capitalize()
choices = ["Rock", "Scissors", "Paper"]
paper = """ _______
---' ____)____
______)
_______)
_______)
---.__________)
"""
scissors = """ _______
---' ____)____
______)
__________)
(____)
---.__(___)
"""
rock = """ _______
---' ____\\_
(_____ )
(_____ )
(_____)
---.____(___)
"""
if user_choice == "Paper":
print(f"Your choice:\n{paper}")
elif user_choice == "Rock":
print(f"Your choice:\n{rock}")
elif user_choice == "Scissors":
print(f"Your choice:\n{scissors}")
elif user_choice not in choices:
print("Invalid choice! Please enter Rock, Scissors, or Paper.")
computer_choice = [paper, scissors, rock]
computer_choice = print(f"Computer choice:\n{random.choice(computer_choice)}")
if user_choice == computer_choice:
print("It's a tie!")
elif user_choice == "Rock" and computer_choice == "Scissors" or \
user_choice == "Scissors" and computer_choice == "Paper" or \
user_choice == "Paper" and computer_choice == "Rock":
print("You win!")
else:
print("Computer wins!")
`
أحسنت ما شاء الله
عندما قمت بتشغيل الكود لاحظت أمرين أحببت تنبيهك عليهما…
الأمر الأول هو أنه في البداية يسأل المستخدم إذا أراد اللعب يضغط enter وإذا أراد التعليمات يكتب help ولكنه يظهر التعليمات سواء كتبت help أو لم اكتب لذا جعلت للـ input متغير وكذلك للتعليمات ثم شرط أن يكتب المستخدم help لكي تظهر التعليمات
play_or_help = input("Press Enter to continue or type (help) for the rules:").lower()
rules = ("************** RULES ***************\n 1) You choose and the computer chooses\n 2) Rock smashes Scissors ==> Rock wins \n 3) Scissors cut Paper ==> Scissors win \n 4) Paper covers Rock ==> Paper wins")
if play_or_help == 'help':
print(rules)
والأمر الثاني هو أنه عندما يعرض اختياري واختيار الكمبيوتر دائما يقول Computer wins سواء كان الكمبيوتر فاز حقا او انا الفائزة او تعادل دائما يجعل الكمبيوتر هو الفائز
عند مراجعة الكود وجدت أن اختيار الكمبيوتر هو اختيار من متغيرات الآسكي فقط ولا يوجد للكمبيوتر اختيار نصي حتى يقارن بينه وبين اجابة المستخدم فأضفت هذه السطور
computer_choice = random.choice(choices)
if computer_choice == "Paper":
print(f"Computer choice:\n{paper}")
elif computer_choice == "Rock":
print(f"Computer choice:\n{rock}")
elif computer_choice == "Scissors":
print(f"Computer choice:\n{scissors}")
السلام عليكم
شكرًا جزيلاً على تصحيحك. هناك الكثير من الأخطاء التي لم ألاحظها، لذا قمت بإعادته من الصفر.
الكود الصحيح:
`import random
print("Welcome to the Rock, Paper, Scissors game!")
user_input = input("Press Enter to continue or type (help) for the rules: ").lower()
if user_input == "help":
print("""
************** RULES ***************
1) You choose, and the computer chooses.
2) Rock smashes scissors → Rock wins.
3) Scissors cut paper → Scissors win.
4) Paper covers rock → Paper wins.""")
rock = """ _______
---' ____\\_
(_____ )
(_____ )
(_____)
---.____(___)
"""
paper = """ _______
---' ____)____
______)
_______)
_______)
---.__________)
"""
scissors = """ _______
---' ____)____
______)
__________)
(____)
---.__(___)
"""
choices = ["Rock", "Paper", "Scissors"]
user_choice = input("Please enter your choice (Rock, Paper, Scissors): ").capitalize()
if user_choice not in choices:
print("Invalid choice! Please enter Rock, Paper, or Scissors.")
#users_choice
if user_choice == "Rock":
print(f"Your choice:\n{rock}")
elif user_choice == "Paper":
print(f"Your choice:\n{paper}")
elif user_choice == "Scissors":
print(f"Your choice:\n{scissors}")
# Computers_choice
computer_choice = random.choice(choices)
print(f"Computer chose: {computer_choice}")
if computer_choice == "Rock":
print(rock)
elif computer_choice == "Paper":
print(paper)
elif computer_choice == "Scissors":
print(scissors)
if user_choice == computer_choice:
print("It's a tie")
elif user_choice == "Rock" and computer_choice == "Scissors" or \
user_choice == "Scissors" and computer_choice == "Paper" or \
user_choice == "Paper" and computer_choice == "Rock":
print("You win! 🎉")
else:
print("Computer wins 💻")
`
وعليكم السلام ورحمة الله
الشكر لله. الكود الجديد جميل ومنظم ما شاء الله