Step 1: The Computer Throws First ๐ค
Time to build Rock Paper Scissors against a computer opponent. โโโ๏ธ
For it to be a fair fight, the computer needs a move you can't predict. You
could use randint, but here you're picking from words, not numbers โ
and that's exactly what random.choice() does:
import random
snacks = ["chips", "apple", "cookie"]
pick = random.choice(snacks)
print(pick)
random.choice() reaches into a list and grabs one item at random. Give
it a list of moves and you've got an opponent.
Your mission
import randomat the top- Make a list called
movesholding"rock","paper"and"scissors" - Use
random.choice(moves)to fill a variable calledcomputer - Print what the computer threw, then run it a few times to see it change!
Your code
Press โถ Run to see what your code does!