Mar 22, 2024

Let's Play Rock, Paper, Scissors!

Hey there! Do you know the game Rock, Paper, Scissors? It's super fun, and now you can play it right here with the computer! Let me show you how it works.

First, you'll need to type your name so we know who's playing. Then, you'll get to choose your move. You can pick rock, paper, or scissors. Just type your choice, and the computer will pick its move too.

After that, it's time to see who wins! If you both pick the same thing, it's a tie. But if one of you picks rock and the other picks scissors, rock wins! Paper beats rock, and scissors beat paper.

It's a simple game, but it's lots of fun! So, give it a try and see if you can beat the computer. Have fun playing!

⁠Here's a step-by-step guide:

1. Open your IDE, like VS Code or any other you like.

⁠2. Create a new folder called "python-game"

3. Inside that folder, create a new file named "rock-paper-scissors.py."

4. Now, copy the code below and paste it into your "rock-paper-scissors.py" file.

import random

name = input()
user_action = input("Enter a choice (rock, paper, scissors): ")
possible_actions = ["rock", "paper", "scissors"]
computer_action = random.choice(possible_actions)
print(f"\n You chose {user_action}, computer chose {computer_action} \n")

if user_action == computer_action:
    print(f"Both players selected {user_action}. It's a tie")
elif user_action == "rock":
    if computer_action == "scissors":
      print(f"Rock beats scissors! {name} wins!")
    else:
      print(f"Paper beats rock! {name} lose!")
elif user_action == "paper":
    if computer_action == "rock":
      print(f"Paper beat rock! {name} wins!")
    else:
      print(f"Scissors beats paper! {name} lose!")
elif user_action == "scissors":
    if computer_action == "paper":
      print(f"Scissors beats paper! {name} wins!")
    else:
      print(f"Rock beats scissors! {name} lose!")

5. Next, open a terminal. You can usually find this in the same place you open your IDE.

6. In the terminal, type "python rock-paper-scissors.py" and then press Enter.

7. Type in your name and then press Enter. After that, you'll see another message asking you to enter your choice (rock, paper, or scissors). Type in your choice and then press Enter again.

And there you go! You've played the game! Now, see if you can beat the computer. Good luck!

Screenshots!

At last,... I lost! 😀


OTHER POSTS

Arduino Project 2: Controlling an LED with a Button

This project demonstrates how to control an LED using a push button with an Arduino UNO. The button will act as the input, and the LED will serve as the output. By pressing the button, we will turn the LED on, and by releasing it, the LED will turn off. This experiment introduces the basic concepts of input and output control using Arduino components.

Read more →

Arduino Project 1: Button State Detection

In this beginner-level Arduino project, we will utilize a simple push button to interact with the Arduino UNO board. The goal is to detect whether the button is pressed or not, with the state displayed on the Serial Monitor. This project serves as an introduction to reading digital input signals using an Arduino and understanding the basic concepts of input-output mechanisms in electronics.

Read more →

My Favorite VS Code Shortcuts

I use some simple VS Code shortcuts to speed up my work.

Read more →

How to Build and Publish NPM Package step-by-step.

Building and publishing an NPM package is a great way to share your code with others. Here's a step-by-step guide on how to create, build, and publish your package.

Read more →