How can I store a number while using multiple if statements? - python

I am creating a python code for rock, paper, scissors but I can't seem to keep track of the score of wins, losses, and ties. I think there is something wrong with my "count" which i called "win += 0", "lose += 0" and "tie += 0." Could someone please tell me what I should do to increase the score by 1 every time there is a win, lose or tie?
Here is my code below:
from random import randint
t = ["rock", "paper", "scissors"]
computer = t[randint(0,2)]
player = False
lose = 0
win = 0
for i in range(0,10):
print("1... 2... 3... go!")
while player == False:
player = input("rock, paper, scissors: ")
print("Computer: ", computer)
print("User: ", player)
if player == computer:
tie = 0
tie +=1
print("Tie!")
elif player == "rock":
if computer == "paper":
lose +=0
print("You lose!")
else:
win +=0
print("You win!")
elif player == "paper":
if computer == "scissors":
lose = 0
lose +=0
print("You lose!")
else:
win +=0
print("You win!")
elif player == "scissors":
if computer == "rock":
lose +=0
print("You lose!")
else:
win +=0
print("You win!")
else:
print("That's not a valid play. Check your spelling!")
player = False
computer = t[randint(0,2)]
break
print("Final Tally")
print("************")
print("User Wins: ", win)
print("Computer Wins: ", lose)
print("Ties: ", tie)
if tie > win and tie > lose:
print("It's a tie!")
elif win > tie and win > lose:
print("You won!")
else:
print("The computer won!")

Here's the fixed version. I suggest you work on it some more :)
from random import choice
t = ["rock", "paper", "scissors"]
tie = 0
lose = 0
win = 0
for i in range(0, 10):
print("1... 2... 3... go!")
# you need to refresh these variables on every for iteration
computer = choice(t)
player = None
# if you're using while to make sure player inputs, that's the only thing that needs
# to be within the while loop
while not player:
player = input("rock, paper, scissors: ")
print("Computer: ", computer)
print("User: ", player)
# I would look for a way to simplify determining the winner
if player == computer:
# tie += 1 is the same as tie = tie + 1
tie +=1
print("Tie!")
elif player == "rock":
if computer == "paper":
lose += 1
print("You lose!")
else:
win += 1
print("You win!")
elif player == "paper":
if computer == "scissors":
lose += 1
print("You lose!")
else:
win += 1
print("You win!")
elif player == "scissors":
if computer == "rock":
lose += 1
print("You lose!")
else:
win += 1
print("You win!")
else:
print("That's not a valid play. Check your spelling!")
print("Final Tally")
print("************")
print("User Wins: ", win)
print("Computer Wins: ", lose)
print("Ties: ", tie)
if tie > win and tie > lose:
print("It's a tie!")
elif win > tie and win > lose:
print("You won!")
else:
print("The computer won!")
UPDATE: Apparently I have nothing to do. So ok, here's a straightforward way to simplify win conditioning.
win_condition_rock = player == 'rock' and computer == 'scissors'
win_condition_paper = player == 'paper' and computer == 'rock'
win_condition_scissors = player == 'scissors' and computer == 'paper'
if player == computer:
# tie += 1 is the same as tie = tie + 1
tie +=1
print("Tie!")
elif any([win_condition_paper, win_condition_scissors, win_condition_rock]):
win += 1
print('You win')
else:
lose += 1
print('You lose')
UPDATE 2: And here's a check for valid input
while player not in t:
player = input("rock, paper, scissors: ").lower()
if player not in t:
print('Invalid input')

Related

Rock, paper, scissors game in Python - some clarification needed

I am writing a simple game of rock, paper and scissors, where the user competes with a computer. There are 5 tries.
The problems I ran into are :
If I enter something apart from three options, it should return "Invalid Entry". Instead, the program stops
The program never prints "You won the game" or "You lost the game", it finishes after 5 attempts
Other feedback would also be appreciated
import random
def game():
win_count = 0
loose_count = 0
tries = 0
while tries < 5:
chosen = input("Make your choice: ")
if chosen == "scissors" or chosen == "Scissors":
element = "scissors"
elif chosen == "paper" or chosen == "Paper":
element = "paper"
elif chosen == "rock" or chosen == "Rock":
element = "rock"
else:
return "Invalid Entry"
computer_choices = ["scissors", "paper", "rock"]
computer_choice = random.choice(computer_choices)
if element == "scissors" and computer_choice == "paper":
print("Computer chose paper, you chose scissors, you win !")
win_count += 1
tries += 1
elif element == "paper" and computer_choice == "scissors":
print("Computer chose scissors, you chose paper, you loose !")
loose_count += 1
tries += 1
elif element == "paper" and computer_choice == "rock":
print("Computer chose rock, you chose paper, you win !")
win_count += 1
tries += 1
elif element == "rock" and computer_choice == "paper":
print("Computer chose paper, you chose rock, you loose !")
loose_count += 1
tries += 1
else:
print("Whoops, that's a draw, try again")
tries+=1
print("Your Wins: "+ str(win_count))
print("Computer Wins: "+str(loose_count))
if win_count > loose_count:
return "Congrats, you won the game!"
else:
return "Sorry, you lost"
game()
return statement does not print anything but they return the value from a function and as soon as a return statement executes the function ends up executing that's why whenever the user inputs something invalid the program stop.
Also not use the if statement from if chosen = paper or chosen = Paper instead use .lower() to lower the string.
I have made some changes to your code.
Try this code
import random
def game():
win_count = 0
loose_count = 0
tries = 0
while tries < 5:
element = input("Make your choice: ").lower()
computer_choices = ["scissors", "paper", "rock"]
if element not in computer_choices:
print("Invalid choice")
continue
computer_choice = random.choice(computer_choices)
if element == "scissors" and computer_choice == "paper":
print("Computer chose paper, you chose scissors, you win !")
win_count += 1
tries += 1
elif element == "paper" and computer_choice == "scissors":
print("Computer chose scissors, you chose paper, you loose !")
loose_count += 1
tries += 1
elif element == "paper" and computer_choice == "rock":
print("Computer chose rock, you chose paper, you win !")
win_count += 1
tries += 1
elif element == "rock" and computer_choice == "paper":
print("Computer chose paper, you chose rock, you loose !")
loose_count += 1
tries += 1
else:
print("Whoops, that's a draw, try again")
tries+=1
print("Your Wins: "+ str(win_count))
print("Computer Wins: "+str(loose_count))
if win_count > loose_count:
print("Congrats, you won the game!")
else:
print("Sorry, you lost")
game()

Sometimes my code doesn't work and sometimes it does

I am creating a rock,paper,scissors game but sometimes my output shows and sometimes it doesn't what's seems to be the problem here?
So far this is my code:
import random
round = 1
win = 0
lose = 0
tie = 0
while True:
choices = ["rock", "paper", "scissors"]
computer = random.choice(choices)
player = None
while player not in choices:
player = input("Rock, paper, or scissors??: ").lower()
if player == computer:
print("Player : ", player)
print("Computer: ", computer)
print("Tie!")
tie+=1
elif player == "rock":
if computer == "paper":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose+=1
elif player == "paper":
if computer == "rock":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win+=1
elif player == "scissors":
if computer == "rock":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose+=1
elif player == "rock":
if computer == "scissors":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win+=1
elif player == "paper":
if computer == "scissors":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose+=1
elif player == "scissors":
if computer == "paper":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win+=1
play_again = input("Would you like to play again? (yes/no): ").lower()
if play_again != "yes":
print("ROUNDS PLAYED: ",round)
print("TOTAL WINS:",win)
print("TOTAL LOSES: ",lose)
print("TOTAL TIME PLAYER TIED WITH COMPUTER: ",tie)
break
elif play_again == "yes":
rounds = round + 1
print("NEW ROUND, ROUND: ",rounds)
print("Bye, Thanks for playing this program")
now if I were to choose paper it won't work it will show me something like this:
(also I have realized that my rounds doesn't count.)
Rock, paper, or scissors??: paper
Would you like to play again? (yes/no): yes
NEW ROUND, ROUND: 2
Rock, paper, or scissors??: paper
Would you like to play again? (yes/no): yes
NEW ROUND, ROUND: 2
Rock, paper, or scissors??: scissors
Player : scissors
Computer: scissors
Tie!
Would you like to play again? (yes/no): yes
NEW ROUND, ROUND: 2
Rock, paper, or scissors??: rock
Player : rock
Computer: rock
Tie!
Would you like to play again? (yes/no): yes
NEW ROUND, ROUND: 2
Rock, paper, or scissors??: paper
Would you like to play again? (yes/no): no
ROUNDS PLAYED: 1
TOTAL WINS: 0
TOTAL LOSES: 0
TOTAL TIME PLAYER TIED WITH COMPUTER: 2
Bye, Thanks for playing this program
I am new to programming any help would be highly appreciated.
You have two different elif block with same conditions. For Example:
elif player == "scissors":
if computer == "rock":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose += 1
elif player == "scissors":
if computer == "paper":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win += 1
In this case, if player choose scissors what is gonna happen?
Python starts to search for this condition but only the first one will be valid.
Thus, you should construct your elif block like this:
elif player == "scissors":
if computer == "paper":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win += 1
elif computer == "rock":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose += 1
Let's look at your second question.
You have a variable named round and rounds. These are same I guess but you are incrementing rounds by the line rounds = round+1.
Instead, try
round = round+1
or
round+=1
Hope this helps.
Your code is not working sometimes because you have not applied all the condition for example what if player choses paper and computer choses rock.
Also the number of round is not increasing because you are saving it in new variable every time, hence not increasing .
rounds = round + 1
above line of code should be
round = round + 1
If you put the same condition more than once in any if-elif structure, only the first conditional if/elif branch will satisfy and the latter will never be executed. For example, in your code in the if-else statement, you have written the same condition elif player == "rock" twice.
elif player == "rock":
if computer == "paper":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose+=1
elif player == "paper":
if computer == "rock":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win+=1
elif player == "scissors":
if computer == "rock":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose+=1
elif player == "rock":
if computer == "scissors":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win+=1
Say, your player has entered rock and computer has chosen scissors. When the code executes, only the first elif player == "rock" will be evaluated, inside this statement, you only checked if the computer has chosen paper or not. But computer has chosen scissors which you did not check in this statement. So, the interpreter will do nothing and skip the rest of the if-else condition.
To make it work, you need to use only one else statement for the same condition, like this:
elif player == "rock":
if computer == "paper":
print("Player : ", player)
print("Computer: ", computer)
print("You lose")
lose+=1
elif computer == "scissors":
print("Player : ", player)
print("Computer: ", computer)
print("You win")
win+=1
You need to follow this for all the possible outcomes.

Python score counter and lives in game with while, if, elif anf else

I'm trying to create this game but I'm stuck with this whole score counter lives and how to break the while loop.
player = input("Welcome! Let's play Rock, Paper, Scissors, Lizard, Spock. You have five lives. Press enter to start.")
from random import randint
t = ["rock", "paper", "scissors", "lizard", "spock"]
computer = t[randint(0,4)]
player = False
while player == False:
lives = 5
score = 0
player = input("rock, paper, scissors, lizard, spock?")
print("Computer plays",computer)
if player == computer:
print("Tie!")
score + 1
elif player == "rock":
if computer == "paper":
print("You lose!", computer, "covers", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif computer == "lizard":
print("You win!", player, "crushes", computer)
score + 2
elif computer == "spock":
print("You lose!", computer, "vaporises", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
else:
print("You win!", player, "smashes", computer)
score + 2
elif player == "paper":
if computer == "scissors":
print("You lose!", computer, "cuts", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif computer == "lizard":
print("You lose!", computer, "eats", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif computer == "spock":
print("You win!", player, "disproves", computer)
score + 2
else:
print("You win!", player, "covers", computer)
score + 2
elif player == "scissors":
if computer == "rock":
print("You lose...", computer, "smashes", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif computer == "spock":
print("You lose!", computer, "smashes", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif computer == "lizard":
print("You win!", player, "decapitates", computer)
score + 2
else:
print("You win!", player, "cuts", computer)
score + 2
elif player == "spock":
if computer == "lizard":
print("You lose!", computer, "poisons", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif computer == "scissors":
print("You win!", player, "smashes", computer)
score + 2
elif computer == "rock":
print("You win!", player, "vaporises", computer)
score + 2
else:
print("You lose!", computer, "disproves", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif player == "lizard":
if computer == "spock":
print("You win!", player, "poisons", computer)
score + 2
elif computer == "rock":
print("You lose!", computer, "crushes", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
elif computer == "paper":
print("You win!", player, "eats", computer)
score + 2
else:
print("You lose!", computer, "decapitates", player)
lives - 1
if lives == 0:
print("Your socre is", score)
break
else:
print("That's not a valid play!")
player = False
computer = t[randint(0,4)]
A few suggestions to get your expected behavior of managing the score counter, lives and how to break the while loop.
Move score and lives above the while-loop.
Even though you are calculating their new values within the loop, their values will reset each loop if they are defined within the loop.
Use increment and decrement operators for calculations.
When doing calculations to assign new values, you'll want to save the result of the calculation back to the variable. Statements like score + 1 and lives - 1 have no effect on those variables until the result gets saved. You could change all score + 1 to score = score + 1 (or score +=1), and similarly change all lives - 1 to lives = lives - 1 (or lives -=1). See Behaviour of increment and decrement operators in Python for more detail.
Remove all break statements.
break is useful if and when you want to break out of the while loop, but since the game keeps playing (I assume, since you keep track of lives) until all lives are lost, then the loop will "break" when the condition lives > 0 is False.
After making these changes, your game should behave as expected.
Hope this helps.
BTW, good job on the game, I enjoyed playing and debugging it!

Comparing user input to a randomly selected list item - Python

I am creating a Rock, Paper, Scissors game for a class. as part of the game I need to have a weapon menu display to the screen for the user to select from. Then the computer will randomly select a weapon from a list. The problem I am facing (I believe) is that the list items range from [0,2] where my menu items list [1,3]. I have searched around for hours, but I don't understand the complex things I have been reading online so I'm not certain how to apply them.
# random integer
from random import randint
# list for weapon
WEAPON = ["Rock", "Paper", "Scissors"]
# one player mode
def onePlayer():
scoreP = 0
scoreC = 0
again = ""
player = False
print("---------------------------------------------")
print("\n\tPlayer VS Computer")
while player == False:
print("Weapons:")
print("1. Rock")
print("2. Paper")
print("3. Scissors")
print("4. Quit")
player = input("\nSelect your weapon: ")
if player == "quit" or player == "q" or player == "4":
player = True
main()
else:
try:
player = int(player)
if player == 1:
player = WEAPON[0]
elif player == 2:
player = WEAPON[1]
elif player == 3:
player = WEAPON[2]
except:
print("please enter a number 1 through 4\n")
computer = WEAPON[randint(0,2)]
if player == computer:
print(player," vs ",computer)
print("It's a tie!\n")
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
elif player == 1:
# computer == paper
if computer == 1:
print(player," vs ",computer)
print("Paper covers rock! You lose!\n")
scoreC = scoreC + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
else:
print("Rock smashes scissors. You win!\n")
scoreP = scoreP + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
elif player == 2:
if computer == 2:
print(player," vs ",computer)
print("Scissors cut paper! You lose!\n")
scoreC = scoreC + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
else:
print("Paper covers rock. You win!\n")
scoreP = scoreP + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
elif player == 3:
if computer == 0:
print(player," vs ",computer)
print("Rock smashes scissors! You lose!\n")
scoreC = scoreC + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
else:
print("Scissors cut paper. You win!\n")
scoreP = scoreP + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
#else:
# print("Please select a valid play option\n")
player = False
Please don't mind the print statements inside the if/else statements. I realize these will need to be changed. My main issue is the logic of comparing user input to the computer's random list selection.
You need to be careful with the contents of your variables:
# this is storing a string
computer = WEAPON[randint(0,2)]
# this expects an integer
elif player == 1:
# computer == paper
if computer == 1:
That would be the root of some of the problems that you are seeing.
Also, in general, when coding try to use meaningful variable names and avoid reusing them for more than one purpose: In this case, two new variables like player_weapon and computer_weapon (instead of reusing player and computer) would have probably prevented your bug. Don't be lazy when declaring variables! ;)
In the if statements, it seems like you are comparing the variable computer, which is a string, to an integer. You assign computer = WEAPON[randint(0,2)], so computer is one of the following: ["Rock", "Paper", "Scissors"]. However, in your if statements, you are saying: if computer == 1: to compare it with the person (your person variable is the same way; you assign a string to it before you compare it to integers).
You just have to make sure you are comparing apples to apples
Compare to the strings, not to the numbers, like this
if player == computer:
print(player," vs ",computer)
print("It's a tie!\n")
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
elif player == 'Rock':
# computer == paper
if computer == 'Paper':
print(player," vs ",computer)
print("Paper covers rock! You lose!\n")
scoreC = scoreC + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
else:
print("Rock smashes scissors. You win!\n")
scoreP = scoreP + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
elif player == 'Paper':
if computer == 'Scissors':
print(player," vs ",computer)
print("Scissors cut paper! You lose!\n")
scoreC = scoreC + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
else:
print("Paper covers rock. You win!\n")
scoreP = scoreP + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
elif player == 'Scissors':
if computer == 'Rock':
print(player," vs ",computer)
print("Rock smashes scissors! You lose!\n")
scoreC = scoreC + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
else:
print("Scissors cut paper. You win!\n")
scoreP = scoreP + 1
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
#else:
# print("Please select a valid play option\n")
player = False
I have condensed a majority of your code by implementing a small dict_map. It could be condensed further but why bother.
# random integer
from random import randint
# list for weapon
WEAPON = ["Rock", "Paper", "Scissors"]
MAPP = {"Rock":{"Win":'Scissors', "Loss":"Paper", "Adj":"Smashes"},
"Paper":{"Win":"Rock", "Loss":"Scissors", "Adj":"Covers"},
"Scissors":{"Win":"Paper", "Loss":"Rock", "Adj":'Cuts'}}
def have_won(player, computer):
#determines if the players choice has beaten the computers
if MAPP[player]["Win"] == computer:
adj = MAPP[player]['Adj']
return True, ' '.join([player, adj, computer])
else:
adj = MAPP[computer]['Adj']
return False, ' '.join([computer, adj, player])
# one player mode
def onePlayer():
scoreP = 0
scoreC = 0
again = ""
player = False
print("---------------------------------------------")
print("\n\tPlayer VS Computer")
while player == False:
print("Weapons:")
print("1. Rock")
print("2. Paper")
print("3. Scissors")
print("4. Quit")
player = input("\nSelect your weapon: ")
if player == "quit" or player == "q" or player == "4":
player = True
else:
try:
player = int(player)
if player == 1:
player = WEAPON[0]
elif player == 2:
player = WEAPON[1]
elif player == 3:
player = WEAPON[2]
except:
print("please enter a number 1 through 4\n")
computer = WEAPON[randint(0,2)]
print player, computer
outcome = have_won(player, computer)
if player == computer:
print(player," vs ",computer)
print("It's a tie!\n")
print("Player:",scoreP,"\nComputer:",scoreC)
print("")
elif outcome[0] == True:
print(outcome[1]+"! You Win!!")
scoreP += 1
elif outcome[0] == False:
print(outcome[1]+"! You Lose!!")
scoreC += 1
#else:
# print("Please select a valid play option\n")
print("Player:",scoreP,"\nComputer:",scoreC)
player = False
onePlayer()

Python Rock Paper Scissors game ( Loop for certain condition )

I made a simple Rock Paper Scissors program, and I need to add a certain condition to this program.. I have to Let the
user play continuously until either the user or the computer wins more than two times in a row.I tried to find the answer in and out but unfortunately couldn't find it..
First off I tried
gameOver = False
playerScore = 0
computerScore = 0
and added
while not gameOver:
main()
if playerScore == 2 :
gameOver = True
and also added playerScore += 1 to the if statements..
But wouldn't work ...
any advise would help and much appreciated in advance.. cheers!
And here is my code..
import random
import sys
def main():
player = input("Enter your choice in number (rock 1 / paper 2 / scissors 0) :")
if (player == 0):
player = "scissors"
elif (player == 1):
player = "rock"
elif (player == 2):
player = "paper"
else:
print("Invalid Input Quitting...")
sys.exit(0)
computer = random.randint(0,2)
if (computer == 0):
computer = "scissors"
elif (computer == 1):
computer = "rock"
elif (computer == 2):
computer = "paper"
if (player == computer):
print("Player is ",player, "Computer is ",computer," You Draw!")
elif (player == "rock"):
if (computer == "paper"):
print("Player is ",player, "Computer is ",computer," You Lost!")
else:
print("Player is ",player, "Computer is ",computer," You Win!")
elif (player == "paper"):
if (computer == "rock"):
print("Player is ",player, "Computer is ",computer," You Win!")
else:
print("Player is ",player, "Computer is ",computer," You Lost!")
elif (player == "scissors"):
if (computer == "rock"):
print("Player is ",player, "Computer is ",computer," You Lost!")
else:
print("Player is ",player, "Computer is ",computer," You Win!")
If you have your main() function return a value corresponding to who won, you could do:
gameOver = False
playerScore = 0
computerScore = 0
while not gameOver:
player_wins = main()
if player_wins == True:
playerScore += 1
computerScore = 0
if player_wins == False:
playerScore = 0
computerScore += 1
if player_wins == None:
# Draw, do nothing to the scores
pass
if playerScore == 2 or computerScore == 2:
print("Game over")
print(" playerScore:", playerScore)
print(" computerScore:", computerScore)
gameOver = True
Note that I had it return True if the player won, False if the computer won, and None if it was a draw.
I think you are asking only a schema:
(this is no true code)
Program starts:
gameover = False
lastWinner = ""
Loop until gameover == True
ask for player answer
make the random choice of the computer
winner = "asigned winner"
if lastWinner == winner:
gameover = True
Print something cool about who is the winner
else:
lastWinner = winner
You may be getting an error when attempting to modify the globals, but from your example it's not entirely clear.
If you try to modify playerScore or computerScore in your main() method, it'll yell at you unless you have a statement like:
global computerScore
before you modify it.
Also, avoid repeating yourself in your code. I was able to trim much of your code out by using the following:
computerWins = False
print "Player is %s; Computer is %s" % (computer, player)
if (player == computer):
print "Draw"
return 0
elif (player == "rock"):
computerWins = computer == "paper"
elif (player == "paper"):
computerWins = computer == "scissors"
elif (player == "scissors"):
computerWins = computer == "rock"
if computerWins:
global computerScore
computerScore = computerScore + 1
print "Computer wins"
else:
global playerScore
playerScore = playerScore + 1
print "You win"

Categories

Resources