Code a rock paper scissors game to play against computer AI with python!! Awesome beginner project!!

LeMaster Tech
183 followers
19 Video Views·Apr 22, 2025
This is part one of a two part tutorial showing how to create the classic guessing game 'rock paper scissors'! In this video we get an input from the player to determine their guess, and then randomly generate an 'AI' computer player's guess and determine who wins or loses by comparing using nested if loops in basic functions!
In the next video we will handle building a game that can be rapidly replayed and reused as well as keeping track of total score!
If you like the content from this page please like and subscribe to the channel to see lots more like this! Thanks so much for supporting the page and good luck coding!
https://www.youtube.com/channel/UCV5Ab39YnXvTZ6Grar9URxQ
hey what's going on you guys welcome
back to the channel i got a fun python
tutorial video for you today uh we'll be
taking a look at building the popular
classic game rock paper scissors in
python
and we're going to build it from scratch
here and i'm just gonna for this video
assume that you have a little bit of
knowledge of either python or
object-oriented programming if you do
have any questions on anything you see
in particular as we go through feel free
to let me know about in the comments
below i'll get back to you as soon as
possible but with no further ado let's
get right into it
um so essentially for rock paper
scissors the player and typically
another player will count down and then
at the same time pick uh whether they
want to be rock paper or scissors and
then each of those can beat one other of
those three and then each of them
will lose to one of those other three so
hopefully you're familiar with the game
and that's why you're here but if not
that's kind of the essence of what we're
doing and i'm going to start programming
it by defining a function that i'm
basically just going to call rock paper
scissors and you don't have to put this
in a function if you don't want but if
you want a scenario where you can keep
playing the function over and over and
over again all you have to do is call
the function so i like to separate code
into functions that way i can call the
function down the road
and essentially every time we start this
function we're going to print out
rock paper scissors one two three
and like that's just the thing that
people say but uh i think it's a good
idea to tell your um to tell your player
what he's playing or she so then a
player is actually going to be an input
where we say
pick
um pick one and then we'll tell them
just enter rp or s
so we don't need to force a user to type
in rock paper or scissors just enter rp
or s
and then let's make the ai
player um
select a
random integer from one to three and
we're going to have to import this so
hopefully uh you're familiar with
python's import
if not
you just at the top of your program you
do import random and then you can access
things like random integer from that
module
okay so what we've just done is we've
grabbed the ai player
um actually let's just call this one ai
because that's going to be a number and
then let's say ai player
equals
let's go ahead and create uh some if
loops and say if ai is equal to one then
we want the ai player to be equal to
rock so i am um
i am doing it this way because i want to
use uh the player and the ai players
answers together to do a comparison to
see if they entered the same thing and
to do that you need them to be the same
string so one two three really
coordinates to rock paper
and scissors
so once we get into um why that is
that'll make a little bit more sense but
for now let's go ahead and leave it that
way
and then let's move on so what we're
going to do then is we're going to
display what both people did so we'll
print out
computer played
and then we will concatenate that with
the ai
player so that's going to tell us what
the player did and then we're going to
print out and and remind the player you
played and in the same format um and
we'll just show them
what they played okay we'll say plus
player
and then now we need to handle scenarios
for actually processing what was done so
uh we'll say if the ai player
is equal to the player so this is you
guys chose the same thing this is the
easiest one right we're just gonna print
uh draw because you tied
and you got to make it a string so be
sure to put inside
quotation marks you can do single or
double quotes with python
and draw was going to be the simplest
one now uh we need to do an l if and say
if player
if the ai chose rock
and the player
chose
scissors so let's make this
let's make this the
lose scenarios for the player so this is
going gonna say if the
pl if the ai picked rock and we picked
scissors
or and let's go ahead and copy this a
couple times
because now we're gonna say
or the ai player picked paper and we
picked rock
and then let's go ahead to a new line
and say or
and the player picked scissors and
we made the mistake of choosing paper
right so um it this really could be
anything if you're not familiar with
rock paper scissors those are just the
rules for
how you lose in rock paper scissors but
so essentially we just created the three
scenarios and in any of those scenarios
we're going to print
loss because you just lost the game and
we could do the exact same code that we
did here
in reverse for the player winning but
since we handled the tie and we handled
a loss already we'll just say else
and print
win okay
so the
three scenarios win loss or tie should
be handled right there
and let's go ahead and see if we just
call the function down below now and say
rock paper rock scissors did i call it
paper rock scissors that's amazing
we're going to change that to rock paper
scissors if you want to leave it paper
rock scissors that's hardcore
and let's go ahead and run it
you know i'm pretty used to finding a
mistake or two on my first time through
but let's see so i'm going to play rock
and the computer played paper and paper
beats rock so we lost let's go ahead and
run that again
um and this time i will play paper and
the computer played paper and we tied
that's cool
and this time i'll play paper again and
they played scissors so i've lost i
haven't managed to win yet but this is
pretty cool you can see the computer is
changing its pick uh just based on a
random integer and then we can pick
whatever we want and it tells us
loss or draw i'm assuming it would tell
us if we win i just haven't yet
but so that's really cool and for this
video that's where i'm going to stop it
this is the basics of
coding some really simple randomly
generated ai to play against
getting operator prompt
user prompts and then um processing data
into an output so uh hopefully you found
this useful be on the lookout for part
two we're going to kind of add features
like replayability and score tracking so
if you have anything in particular you
want to see make sure to check out that
part two that'll be coming out because
that might cover your questions or let
me know about in the comments below if
you found this or anything else on the
channel useful i really appreciate
liking the subscribe it helps the
channel out a ton and as always good
luck with your code and thanks for
watching thanks bye
