Created
October 14, 2023 20:26
-
-
Save TanjimReza/dfa25004c920ac46279c6c98078e02d7 to your computer and use it in GitHub Desktop.
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
import random | |
all_choices = ["rock", "paper", "scissors"] | |
n = int(input("Rounds:")) | |
def playRockPaperScissor(rounds): | |
your_points = 0 | |
pc_points = 0 | |
for i in range(rounds): | |
your_choice = all_choices.index(input("Enter your choice:")) | |
pc_choice = all_choices.index(random.choices(all_choices)[0]) | |
if not (your_choice == 0 and pc_choice == 2) \ | |
or (your_choice == 2 and pc_choice == 0): | |
if your_choice > pc_choice: | |
pc_points += 1 | |
else: | |
your_points += 1 | |
else: | |
if your_choice < pc_choice: | |
your_points += 1 | |
else: | |
pc_points += 1 | |
print(f"Your choice: {all_choices[your_choice]} - PC choice: {all_choices[pc_choice]}") | |
print(f"Your points: {your_points} - PC points: {pc_points}") | |
return your_points > pc_points | |
result = playRockPaperScissor(n) | |
if result: | |
print("You Won!") | |
else: | |
print("PC Won!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment