سورس بازی سنگ کاغذ قیچی در پایتون

سورس بازی سنگ کاغذ قیچی در پایتون

قطعا بازی بازی سنگ کاغذ قیچی رو همه کاربران باهاش آشنایی دارند. در این مطلب، سورس این بازی ساده رو برای عزیزان مبتدی پایتون کار قرار دادیم.

 

سورس بازی سنگ کاغذ قیچی در پایتون

در بازی سنگ، کاغذ و قیچی هدف ما ایجاد یک بازی خط فرمان است که در آن کاربر می‌تواند بین سنگ، کاغذ و قیچی یکی را انتخاب کند و کاربر در صورت برنده شدن، امتیاز دریافت کرده که در انتهای بازی امتیاز کسب شده به آن نمایش داده می شود.

import random
choices = ["Rock", "Paper", "Scissors"]
computer = random.choice(choices)
player = False
cpu_score = 0
player_score = 0
while True:
    player = input("Rock, Paper or  Scissors?").capitalize()
    ## Conditions of Rock,Paper and Scissors
    if player == computer:
        print("Tie!")
    elif player == "Rock":
        if computer == "Paper":
            print("You lose!", computer, "covers", player)
            cpu_score+=1
        else:
            print("You win!", player, "smashes", computer)
            player_score+=1
    elif player == "Paper":
        if computer == "Scissors":
            print("You lose!", computer, "cut", player)
            cpu_score+=1
        else:
            print("You win!", player, "covers", computer)
            player_score+=1
    elif player == "Scissors":
        if computer == "Rock":
            print("You lose...", computer, "smashes", player)
            cpu_score+=1
        else:
            print("You win!", player, "cut", computer)
            player_score+=1
    elif player=='End':
        print("Final Scores:")
        print(f"CPU:{cpu_score}")
        print(f"Plaer:{player_score}")
        break

خروجی به شکلی زیر است :

Rock, Paper or Scissors?rock
Tie!
Rock, Paper or Scissors?paper
You win! Paper covers Rock
Rock, Paper or Scissors?scissors
You lose… Rock smashes Scissors
Rock, Paper or Scissors?end
Final Scores:
CPU:1
Plaer:1

با ادیتور آنلاین سورس را اجرا کنید

ایجاد این نوع بازی ها به یک مبتدی کمک می کند تا منطقی فکر کند. حتی می توانید از این ایده برای ساخت بازی خود استفاده کنید.

پکیج ویژه : آموزش پروژه محور طراحی سایت با پایتون و جنگو مختص بازار کار

در پایان، ایجاد این نوع برنامه ها به شما کمک می کند تا الگوریتم های خود را بسازید که مهارت بسیار مهمی برای کدنویسی مصاحبه ها و برنامه نویسی رقابتی است.

 

مطالب مرتبط با سورس برنامه نویسی پایتون

  1. سورس اختصاری کردن کلمات در پایتون
  2. سورس Alarm Clock با پایتون
  3. سورس ساخت داستان تصادفی در پایتون
  4. سورس ساخت پسورد تصادفی در پایتون

 

Rock, Paper and Scissors Game with Python

In this article, I’ll walk you through how to make a rock, paper, and scissors game with Python. In the rock, paper and scissors game our goal is to create a command-line game where a user has the option to choose between rock, paper and scissors and if the user wins the score is added, and at the end when the user finishes the game, the score is shown to the user.

To create the Rock, Paper and Scissors game with Python, we need to take the user’s choice and then we need to compare it with the computer choice which is taken using the random module in Python from a list of choices, and if the user wins then the score will increase by 1

Creating these types of games will help a beginner to think logically. You can even use this idea to make your own game. In the end, creating these types of programs will help you create your algorithms, which is a very important skill for coding interviews and competitive programming.

5/5 - (2 امتیاز)

راستی! برای دریافت مطالب جدید در کانال تلگرام یا پیج اینستاگرام سورس باران عضو شوید.

پکیج آموزش برنامه‌ نویسی پایتون در 24 ساعت
  • انتشار: ۱ بهمن ۱۴۰۱

دسته بندی موضوعات

آخرین محصولات فروشگاه

مشاهده همه

نظرات

  1. سلام.خیلی سورس مفید و تمیزی بود فقط یک مشکل داره اون هم اینکه وقتی هر بار ما (یعنی player) یک گزینه رو میزنم مثلا Paper در اون صورت اگه کامپیوتر هم Paper باشه تا اخر بازی، کامپیوتر روی حالت Paper باقی می مونه.که برای رفع این مشکل باید این خط کد رو به اخر حلقه ی while اضافه کرد:
    computer = random.choice(choices)
    موفق باشید.

    • صابر بوستانی
      22 فروردین 1402

      سلام. ممنون از توضیحات شما

بازخوردهای خود را برای ما ارسال کنید

این سایت از اکیسمت برای کاهش هرزنامه استفاده می کند. بیاموزید که چگونه اطلاعات دیدگاه های شما پردازش می‌شوند.