Created
October 12, 2019 10:49
-
-
Save MM-coder/7271bf8923190c34a73809db06093637 to your computer and use it in GitHub Desktop.
Dynamically typed rock paper scissors game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Interactive @ https://repl.it/@ItsMMgamer/EminentNavajowhiteLanserver | |
import random | |
choices = ['rock', 'paper', 'scissors'] | |
user_list = ['rock:scissors', 'scissors:paper', 'paper:rock', 'scissors:rock'] | |
computer_choice = random.choice(choices) | |
user_choice = str(input('Rock, Paper, Scissors?')) | |
def user_win(composed: str): | |
list_tuple = composed.split(':') | |
print('-'*32) | |
print(f"Computer picks: {list_tuple[1]} and user picks {list_tuple[0]}") | |
print("User Wins!") | |
print('-'*32) | |
def user_lose(composed: str): | |
list_tuple = composed.split(':') | |
print('-'*32) | |
print(f"Computer picks: {list_tuple[1]} and user picks {list_tuple[0]}") | |
print("User Loses!") | |
print('-'*32) | |
def user_tie(composed: str): | |
list_tuple = composed.split(':') | |
print('-'*32) | |
print(f"Computer picks: {list_tuple[1]} and user picks {list_tuple[0]}") | |
print("TIE!") | |
print('-'*32) | |
def rps(computer_choice, user_choice): | |
do_composed = user_choice.lower() + ':' + computer_choice | |
if do_composed in user_list: | |
user_win(do_composed) | |
elif computer_choice == user_choice.lower(): | |
user_tie(do_composed) | |
else: | |
user_lose(do_composed) | |
rps(computer_choice, user_choice) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment