Last active
June 2, 2017 09:23
-
-
Save jatinkrmalik/89822bfaf358ad0732e8a4ba57edb446 to your computer and use it in GitHub Desktop.
Stone | Paper | Scissors
This file contains 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
# Stone Paper Scissors | |
import random | |
import os | |
def cls(): # to clear the screen | |
os.system('cls' if os.name == 'nt' else 'clear') | |
def match_up(user_ch): | |
op = ["Stone", "Paper", "Scissors"] | |
comp_ch = random.choice(op) | |
print("\nMATCH UP!\n") | |
print(">>You chose: {}\n>>Computer chose: {}\n".format(user_ch, comp_ch)) | |
if user_ch == comp_ch: | |
print("Whoops! Same same! Try again...") | |
return 0 | |
elif user_ch == "Stone": | |
if comp_ch == "Scissors": | |
print("You win! Stone slams the scissors! xD") | |
return 1 | |
elif comp_ch == "Paper": | |
print("You lose! Paper wraps around the stone! :(") | |
return -1 | |
elif user_ch == "Paper": | |
if comp_ch == "Stone": | |
print("You win! Paper wraps around the stone! ^_^") | |
return 1 | |
elif comp_ch == "Scissors": | |
print("You lose! Scissors glides through the paper. :x") | |
return -1 | |
elif user_ch == "Scissors": | |
if comp_ch == "Paper": | |
print("You win! Scissors glides through the paper! :D") | |
return 1 | |
elif comp_ch == "Stone": | |
print("Whoops! You lose! Stone will smash your scissors. :/") | |
return -1 | |
input() # to wait for user to continue | |
def main(): | |
user_score, computer_score = 0, 0 | |
while True: | |
cls() | |
flag = 0 | |
print("\n\t\tWelcome to STONE|PAPER|SCISSORS!\n") | |
print("\t\t\tUser - {}\t Computer - {}".format(user_score, computer_score)) | |
user_ch = input("\nSelect from the following options:\n(S) Stone \t(P) Paper \t(X) Scissors\n\n>>Enter your choice: ").lower() | |
choice = {"s": "Stone", "p": "Paper", "x": "Scissors"} | |
flag = match_up(choice.get(user_ch, "\n\n***Wrong choice entered, try again***")) | |
if flag == 1: | |
user_score += 1 | |
elif flag == -1: | |
computer_score += 1 | |
input() # to wait for user to continue | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment