ROCK, PAPER, SCISSORS ✂




Picture this, it’s 2024 and you are still playing rock paper scissors using your hands. Too corny? Okay let's think of a better headline like maybe"2024! The age where we play rock paper scissors on our computers". I know I know there is an easier way to play rock paper scissors but come on now, is this not impressive to show your friends instead? This is a fun project  to do if you are just starting out in Python and need to get your hands dirty.

What you need to know?

Basic python knowledge which in this case is: How to print and how to use a bunch of else and elif statements, no seriously that is it! In case you have no idea how to do this ,I got you boo💋! You can find a tutorial about else and elif statements here.

Our first line of the code is to import getpass, in case you do not have it you can install it using pip in your terminal.



The purpose of getpass is to prevent each  player from viewing their opponent's input .
We proceed with a couple of  print statements to welcome the players and explain how the rules of the game work.
Create two variables for each player as demonstrated below and make the variable input statements to prompt the users to enter a value. This code supports two players but since you are the creator you can always add more players by creating another variable.



We then use a bunch of elif statements coupled with print statements to make the logic part of the game i.e. if player one inputs a rock and player two inputs paper, who wins and so on and so forth.

 







Now because I am just cool like that😎, my print statements are, well, you know, awesome! This should not limit you however, you can structure your statements however you see best as long as the logic makes sense.


Now rock on(haha I just had to)dude. You can find the full code here.

Let me know what you thought about this, did you learn anything, where can improvements be made?

Comments

  1. A very fun and interactive way of teaching n learning
    Amazing work!

    ReplyDelete

Post a Comment

Popular Posts