Friday, 4 September 2026

๐Ÿš€ Day 107/150 – Rock Paper Scissors Game in Python

 



๐Ÿš€ Day 107/150 – Rock Paper Scissors Game in Python


Rock Paper Scissors is a simple and fun Python game where the player competes against the computer. It is a great beginner project for practicing random selection, user input, conditions, and comparison operators.

In this post, we'll explore three short ways to create a Rock Paper Scissors game in Python.

Method 1 – Basic Game ๐ŸŽฎ

The simplest version randomly selects a choice for the computer.

import random p = input("Choose: ") c = random.choice(["rock", "paper", "scissors"]) print("You:", p, "Computer:", c)







Sample Output
Choose: rock
You: rock Computer: scissors

Explanation

random.choice() randomly selects one option from the list.

The user's choice is stored in p, while the computer's choice is stored in c.

This is the basic foundation of the game.

Method 2 – Win or Lose ๐Ÿ†

We can add simple conditions to determine whether the player wins.

import random p = input("Choose: ") c = random.choice(["rock", "paper", "scissors"]) print("Win!" if (p=="rock" and c=="scissors") or (p=="paper" and c=="rock") or (p=="scissors" and c=="paper") else "Lose!")








Sample Output
Choose: paper
Win!

Explanation

The conditions check the three possible winning combinations:

Rock beats Scissors
Paper beats Rock
Scissors beats Paper

If one of these conditions is true, "Win!" is displayed. Otherwise, "Lose!" is displayed.

Method 3 – Win, Lose or Tie ๐Ÿค

We can also handle the situation when both players choose the same option.


import random p = input("Choose: ") c = random.choice(["rock", "paper", "scissors"]) print("Tie!" if p==c else "Win!" if (p=="rock" and c=="scissors") or (p=="paper" and c=="rock") or (p=="scissors" and c=="paper") else "Lose!")









Sample Output
Choose: rock
Tie!

Explanation

First, the program checks whether both choices are the same.

If p == c, the result is "Tie!".

Otherwise, it checks the winning combinations. If none match, the player loses.

๐Ÿ“Š Comparison of Methods
Method Best For
Basic Game Learning random choices
Win or Lose Practicing conditions
Win, Lose or Tie Building complete game logic


๐Ÿ”ฅ Key Takeaways
random.choice() is useful for randomly selecting the computer's move.
input() takes the player's choice.
if conditions can determine the winner.
and and or help combine multiple game rules.
Comparing both choices allows us to detect a tie.
Rock Paper Scissors is a simple project for practicing Python logic.

๐ŸŽฎ Small games like this are a great way to turn Python fundamentals into interactive projects!

๐Ÿš€ Stay tuned for Day 108 of the #150DaysOfPython series!









0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (119) AI (343) Android (25) AngularJS (1) Api (7) Assembly Language (2) aws (31) Azure (12) BI (10) book (1) Books (351) Bootcamp (14) C (78) C# (12) C++ (83) cloud (1) Course (90) Coursera (303) Cybersecurity (36) data (10) Data Analysis (46) Data Analytics (31) data management (16) Data Science (427) Data Strucures (18) Deep Learning (219) Django (16) Downloads (3) edx (21) Engineering (15) Euron (30) Events (7) Excel (24) Finance (13) flask (4) flutter (1) FPL (17) Generative AI (77) Git (13) Google (54) Hadoop (3) HTML Quiz (1) HTML&CSS (48) IBM (43) IoT (3) IS (25) Java (99) Leet Code (4) Machine Learning (399) Meta (24) MICHIGAN (5) microsoft (13) Nvidia (8) Pandas (16) PHP (20) Projects (35) Python (1365) Python Coding Challenge (1230) Python Library (1) Python Mathematics (15) Python Mistakes (51) Python Pattern Challenge (1) Python Quiz (619) Python Tips (111) pythonquiz (1) Questions (3) R (72) React (7) Scripting (3) security (4) Selenium Webdriver (4) Software (21) SQL (55) Udemy (20) UX Research (1) web application (11) Web development (9) web scraping (3)

Followers

Python Coding for Kids ( Free Demo for Everyone)