Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created September 23, 2021 03:13
Show Gist options
  • Save shinysu/24eaa25ef4a960a2604054f72531780b to your computer and use it in GitHub Desktop.
Save shinysu/24eaa25ef4a960a2604054f72531780b to your computer and use it in GitHub Desktop.
Day 5
from random import randint
num = randint(1, 10)
guess = None
while guess != num:
guess = input("guess a number between 1 and 10: ")
guess = int(guess)
if guess == num:
print("congratulations! you won!")
break
else:
print("nope, sorry. try again!")
import random
user_action = input("Enter a choice (rock, paper, scissors): ")
possible_actions = ["rock", "paper", "scissors"]
computer_action = random.choice(possible_actions)
print(f"\nYou 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("Rock smashes scissors! You win!")
else:
print("Paper covers rock! You lose.")
elif user_action == "paper":
if computer_action == "rock":
print("Paper covers rock! You win!")
else:
print("Scissors cuts paper! You lose.")
elif user_action == "scissors":
if computer_action == "paper":
print("Scissors cuts paper! You win!")
else:
print("Rock smashes scissors! You lose.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment