Last active
February 15, 2022 00:34
-
-
Save bharddwaj/e753199bdd55c0454bca4aed775ec213 to your computer and use it in GitHub Desktop.
rock paper scissors in python for practice.
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; | |
def computerChoice(): | |
random.seed() | |
a = random.randint(1,3); | |
if(a == 1): | |
computer = "rock" | |
elif(a == 2): | |
computer = "scissors" | |
elif(a == 3): | |
computer = "paper" | |
return computer | |
b = 1 | |
while(b == 1): | |
print("How many times do you wish to play?") | |
play = (int)(input()) | |
for i in range (0, play): ##Note to self: this is correct because python excludes the stop range. For instance if I enter 3, it will go 0,1,2 | |
computerChoice(); | |
print("type either rock, paper, or scissors.") | |
user = input() | |
if(user.lower() == "rock" and computerChoice().lower() == "rock"): | |
print("tie") | |
elif (user.lower() == "scissors" and computerChoice().lower() == "scissors"): | |
print("tie") | |
elif (user.lower() == "paper" and computerChoice().lower() == "paper"): | |
print("tie") | |
elif (user.lower() == "rock" and computerChoice().lower() == "scissors"): | |
print("win") | |
elif (user.lower() == "scissors" and computerChoice().lower() == "paper"): | |
print("win") | |
elif (user.lower() == "paper" and computerChoice().lower() == "rock"): | |
print("win") | |
elif (user.lower() == "scissors" and computerChoice().lower() == "rock"): | |
print("lose") | |
elif (user.lower() == "paper" and computerChoice().lower() == "scissors"): | |
print("lose") | |
elif (user.lower() == "rock" and computerChoice().lower() == "paper"): | |
print("lose") | |
print("if you wish to continue type 1 but if not type any other number") | |
b = (int)(input()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment