Created
October 9, 2022 12:12
-
-
Save 4193883-eng/a6012d63d7c93c89143cd1528a9bdb75 to your computer and use it in GitHub Desktop.
homework3
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
import random | |
def game(result): | |
print("") | |
print("====== Start Game: Rock, Paper, Scissors! ======") | |
while result['computer'] == 3 or result['player'] == 3: | |
choice = input("Select R / P / S / L / Z(spock) >>") | |
computer_choice = random.choice("rpslz") | |
print('You selected ---', str.capitalize(choice)) | |
if str.lower(choice) == computer_choice: | |
print("Draw") | |
elif str.lower(choice) == "r" and (computer_choice == "p" or computer_choice == 'z'): | |
result["computer"] += 1 | |
print('Computer Won! Better luck next time!') | |
elif str.lower(choice) == "r" and (computer_choice == "s" or computer_choice == 'l'): | |
result["player"] += 1 | |
print('You Won!') | |
elif str.lower(choice) == "p" and (computer_choice == "r" or computer_choice == 'z'): | |
result["player"] += 1 | |
print('You Won!') | |
elif str.lower(choice) == "p" and (computer_choice == "s" or computer_choice == 'l'): | |
result["computer"] += 1 | |
print('Computer Won! Better luck next time!') | |
elif str.lower(choice) == "s" and (computer_choice == "r" or computer_choice == 'z'): | |
result["computer"] += 1 | |
print('Computer Won! Better luck next time!') | |
elif str.lower(choice) == "s" and (computer_choice == "p" or computer_choice == 'l'): | |
result["player"] += 1 | |
print('You Won!') | |
elif str.lower(choice) == 'z' and (computer_choice == "p" or computer_choice == "l"): | |
result["computer"] += 1 | |
elif str.lower(choice) == 'z' and (computer_choice == "r" or computer_choice == "s"): | |
result["player"] += 1 | |
elif str.lower(choice) == 'l' and (computer_choice == "r" or computer_choice == "s"): | |
result["computer"] += 1 | |
elif str.lower(choice) == 'l' and (computer_choice == "p" or computer_choice == "z"): | |
result["player"] += 1 | |
print("Score, Computer", result["computer"], result["player"]) | |
if result['computer'] == 3: | |
print('Computer won 3 times!!!') | |
else: | |
print("Player won 3 times!!!") | |
result = {"computer": 0, "player": 0} | |
play = True | |
while play: | |
game(result = result) | |
if (input("Do you want to play again? Y/n >>> ")).lower() == 'y': | |
play = True | |
else: | |
play = False | |
print("Score, Computer", result["computer"], result["player"]) | |
print('Bye!!!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment