Created
November 30, 2017 03:00
-
-
Save azdafirmansyah/a14af37fc6d62aba673e55a6f074362d to your computer and use it in GitHub Desktop.
Rock Paper Scissors Exercise
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
#1 = Rock | |
#2 = Scissors | |
#3 = Paper | |
# Exercise URL : http://www.practicepython.org/exercise/2014/03/26/08-rock-paper-scissors.html | |
def CheckInput(user_input): | |
if user_input < 1 or user_input > 3: | |
print("Only allow 1,2 or 3 number\nLet's Try Again\n----------------------\n") | |
return False | |
else: | |
return True | |
dict_game = {1:'Rock',2:'Scissors',3:'Paper'} | |
while True: | |
try: | |
user_one = int(input("User One please input your choose : \n > ")) | |
if CheckInput(user_one): | |
print("user One Choose ", dict_game.get(user_one)) | |
user_two = int(input("User Two please input your choose : \n > ")) | |
if CheckInput(user_two): | |
print("user Two Choose ", dict_game.get(user_two)) | |
if user_one == user_two: | |
print("Draw, please Try input again") | |
elif user_one == 1: | |
if user_two == 2: | |
print("User One Wins (Rock Beat Scissor)") | |
elif user_two == 3: | |
print("User Two Wins (Paper Beat Rock)") | |
elif user_one == 2: | |
if user_two == 1: | |
print("User Two Wins (Rock Beat Scissor)") | |
elif user_two == 3: | |
print("User One Wins (Scissors Beat Paper)") | |
elif user_one == 3: | |
if user_two == 1: | |
print("User One Wins (Paper Beat Rock)") | |
elif user_two == 2: | |
print("User Two Wins (Scissors Beat Paper)") | |
confirmation = input("Do you want to continue ? \n1. Y (To Continue)\n2. Any Key to Stop\n > ") | |
if confirmation == 'Y' or confirmation == 'y': | |
print("\nLet's Try Again\n----------------------") | |
else: | |
print("\nThanks a lot") | |
break | |
except Exception as error: | |
print("Please input valid number!\nLet's Try Again\n----------------------") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment