From 8f23161f5b32af035383776841ca7b12b515a6fd Mon Sep 17 00:00:00 2001 From: VishGit1234 <> Date: Mon, 2 Nov 2020 09:15:33 -0500 Subject: [PATCH 1/2] Update RockPaperScissors.py --- RockPaperScissors.py | 75 +++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/RockPaperScissors.py b/RockPaperScissors.py index b7cc796..19a9c84 100644 --- a/RockPaperScissors.py +++ b/RockPaperScissors.py @@ -1,44 +1,83 @@ ## # -# Author: FX Coding Club -# Date 9/24/2020 +# Author: VishGit1234 +# Date 11/2/2020 # - +import random +from random import randint # These are the possible choices in the game, using the randint function, the computer will be a choice based on the integer it chooses -list = ['rock', 'paper', 'scissors'] +list = ['rock', 'paper', 'scissors', 'spock', 'lizard'] + +# Assign a random valid choice to computerChoice (computer answer) +computerChoice = list[randint(0, 2)] +# Get user input and store +isValid = False +while isValid == False: + print('Input one of the following; rock, paper, scissors, spock or lizard') + Choice = input() + Choice = Choice.lower() + for i in list: + if Choice == i: + isValid = True + if isValid == False: + print(Choice + ' is an incorrect input') -# Compare var1 and computerChoice to see who wins +# Compare Choice and computerChoice to see who wins # The following is all the comparisons if the computer chooses "Rock" -if computerChoice == 'rock' and var1 == 'scissors'): - print('You chose ' + var1 + ' and the computer chose ' + +if computerChoice == 'rock' and Choice == 'scissors': + print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', The computer wins!') -elif computerChoice == 'rock' and var1 == 'paper'): - print('You chose ' + var1 + ' and the computer chose ' + +elif computerChoice == 'rock' and Choice == 'paper': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', You win!') + +elif computerChoice == 'rock' and Choice == 'spock': + print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', You win!') +elif computerChoice == 'rock' and Choice == 'lizard': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', The computer wins!') + # The following is all the comparisons if the computer chooses "Paper" -elif computerChoice == 'paper' and var1 == 'rock'): - print('You chose ' + var1 + ' and the computer chose ' + +elif computerChoice == 'paper' and Choice == 'rock': + print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', The computer wins!') -elif computerChoice == 'paper' and var1 == 'scissors'): - print('You chose ' + var1 + ' and the computer chose ' + +elif computerChoice == 'paper' and Choice == 'scissors': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', You win!') + +elif computerChoice == 'paper' and Choice == 'spock': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', The computer wins!') + +elif computerChoice == 'paper' and Choice == 'lizard': + print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', You win!') # The following is all the comparisons if the computer chooses "Scissors" -elif computerChoice == 'scissors' and var1 == 'paper'): - print('You chose ' + var1 + ' and the computer chose ' + +elif computerChoice == 'scissors' and Choice == 'paper': + print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', The computer wins!') -elif computerChoice == 'scissors' and var1 == 'rock'): - print('You chose ' + var1 + ' and the computer chose ' + +elif computerChoice == 'scissors' and Choice == 'rock': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', You win!') + +elif computerChoice == 'scissors' and Choice == 'spock': + print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', You win!') +elif computerChoice == 'scissors' and Choice == 'lizard': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', The computer wins!') + # The case in which both the computer and the user chose the same one, and they tie else: - print('You chose ' + var1 + ' and the computer chose ' + + print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', you tied!') From eca48b7632fa42c8050b91b1f4d4cdd055140c99 Mon Sep 17 00:00:00 2001 From: VishGit1234 <> Date: Mon, 2 Nov 2020 09:25:28 -0500 Subject: [PATCH 2/2] Added spock and lizard to computer choices --- RockPaperScissors.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/RockPaperScissors.py b/RockPaperScissors.py index 19a9c84..9d18868 100644 --- a/RockPaperScissors.py +++ b/RockPaperScissors.py @@ -10,7 +10,7 @@ list = ['rock', 'paper', 'scissors', 'spock', 'lizard'] # Assign a random valid choice to computerChoice (computer answer) -computerChoice = list[randint(0, 2)] +computerChoice = list[randint(0, 4)] # Get user input and store isValid = False @@ -77,6 +77,40 @@ print('You chose ' + Choice + ' and the computer chose ' + computerChoice + ', The computer wins!') +# The following is all the comparisons if the computer chooses "Spock" +elif computerChoice == 'spock' and Choice == 'paper': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', You win!') + +elif computerChoice == 'spock' and Choice == 'rock': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', The computer wins!') + +elif computerChoice == 'spock' and Choice == 'scissors': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', The computer wins!') + +elif computerChoice == 'spock' and Choice == 'lizard': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', You win!') + +# The following is all the comparisons if the computer chooses "Lizard" +elif computerChoice == 'lizard' and Choice == 'paper': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', The computer wins!') + +elif computerChoice == 'lizard' and Choice == 'rock': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', You win!') + +elif computerChoice == 'lizard' and Choice == 'scissors': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', You win!') + +elif computerChoice == 'lizard' and Choice == 'spock': + print('You chose ' + Choice + ' and the computer chose ' + + computerChoice + ', The computer wins!') + # The case in which both the computer and the user chose the same one, and they tie else: print('You chose ' + Choice + ' and the computer chose ' +