DEV Community

mikekameta
mikekameta

Posted on

100 Days of Code: The Complete Python Pro Bootcamp for 2022 - Day 4 (Rock Paper Scissors)

Excercise 4.1 Heads or Tails

import random

random_side = random.randint(0, 1)
if random_side == 1:
print("Heads")
else:
print("Tails")
Enter fullscreen mode Exit fullscreen mode

Exercise 4.2 Banker Roulette

When running the code it will ask for a seed number. import random

List of names to use are Angela, Ben, Jenny, Michael, Chole

import random

🚨 Don't change the code below 👇
test_seed = int(input("Create a seed number: "))
random.seed(test_seed)

-Split string method
names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(", ")
🚨 Don't change the code above 👆

Write your code below this line 👇

-Get total items in a list using len().
num_items = len(names)

-Generate random numbers between 0 and the last index
random_choice = random.randint(0, num_items -1)

-Pick a random person to pay selected from random_choice
pay_the_bill = names[random_choice]

print(pay_the_bill + " is going to buy the meal today!")
Enter fullscreen mode Exit fullscreen mode

Exercise 4.3 Treasure Map

row1 = ["⬜️","️⬜️","️⬜️"]
row2 = ["⬜️","⬜️","️⬜️"]
row3 = ["⬜️️","⬜️️","⬜️️"]
map = [row1, row2, row3]
print(f"{row1}\n{row2}\n{row3}")

position = input("Where do you want to put the treasure? ")

-write your code below
horizontal = int(position[0])
vertical = int(position[1])

map[vertical - 1][horizontal - 1] = "X"
-write your code above
Enter fullscreen mode Exit fullscreen mode

Project 4 Rock Paper Scissors

import random

rock = '''
_______
---' _)
()
()
()
---.(__)
'''

paper = '''
_______
---' _)_
___)
_)
_)
---._______)
'''

scissors = '''
_______
---' _)_
___)
____)
()
---.(__)
'''
# Write your code below this line 👇
game_images = [rock, paper, scissors]

user_choice = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.\n"))
print(game_images[user_choice])

computer_choice = random.randint(0, 2)
print("Computer chose:")
print(game_images[computer_choice])

if user_choice >= 3 or user_choice < 0:
  print("You typed an invalid number, you lose!")
elif user_choice == 0 and computer_choice == 2:
  print("You win!")
elif computer_choice == 0 and user_choice == 2:
  print("You lose")
elif computer_choice > user_choice:
  print("You lose")
elif user_choice > computer_choice:
  print("You win!")
elif computer_choice == user_choice:
  print("It's a draw")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)