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
Use npm scripts to Simplify Daily Tasks
Running long terminal commands over and over? Automate them with simple npm scripts in your package.json.
Read more →Learn Faster with Browser DevTools Tricks
Your browser is more powerful than you think. Chrome/Edge/Firefox DevTools can save you tons of time debugging and experimenting directly in the browser.
Read more →Fix "Email in this signature doesn't match the committer email" on GitHub
Pushed a signed GPG commit only to get a warning that the signature is unverified because of an email mismatch? Here is how to sync your GPG identity with Git.
Read more →How to Set Up Verified GPG Commit Signing on GitHub
Tired of seeing the "Unverified" badge on your GitHub commits? Setting up a GPG key signs your commits cryptographically, proving to your team (and future employers) that the code actually came from you.
Read more →