summaryrefslogtreecommitdiff
path: root/rock_paper_scissors.py
diff options
context:
space:
mode:
authorroot <root@annapurna.annapurna.fitness>2025-07-09 16:04:21 +0200
committerroot <root@annapurna.annapurna.fitness>2025-07-09 16:04:21 +0200
commitca5f1b4e499e2e0a3d16e228a65b27350feaca1f (patch)
tree8328925f189fde97e3da38959c2992330934a3c4 /rock_paper_scissors.py
initial commitHEADmaster
Diffstat (limited to 'rock_paper_scissors.py')
-rwxr-xr-xrock_paper_scissors.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/rock_paper_scissors.py b/rock_paper_scissors.py
new file mode 100755
index 0000000..cbabb97
--- /dev/null
+++ b/rock_paper_scissors.py
@@ -0,0 +1,42 @@
+import random
+
+user_wins = 0
+computer_wins = 0
+
+options = ["rock", "paper", "scissors"]
+
+while True:
+ user_input = input("Type Rock/Paper/Scissors or Q to quit: ").lower()
+ if user_input == "q":
+ break
+
+ if user_input not in options:
+ continue
+
+ random_number = random.randint(0, 2)
+ # rock: 0, paper: 1, scissors: 2
+ computer_pick = options[random_number]
+ print("Computer picked", computer_pick + ".")
+
+ if user_input == "rock" and computer_pick == "scissors":
+ print("You won!")
+ user_wins = user_wins + 1
+
+ elif user_input == "scissors" and computer_pick == "paper":
+ print("You won!")
+ user_wins = user_wins + 1
+
+ elif user_input == "paper" and computer_pick == "rock":
+ print("You won!")
+ user_wins = user_wins + 1
+
+ elif user_input == computer_pick:
+ print("DRAW")
+
+ else:
+ print("You lost!")
+ computer_wins = computer_wins + 1
+
+print("You won", user_wins, "times.")
+print("The computer won", computer_wins, "times.")
+print("Goodbye!") \ No newline at end of file