I'm new to coding and my Rock Paper and Scissors game that i've created isn't working as intended.
If someone enters the word rock, paper or scissors, then the programme works as intended.
However, when the someone enters a word other than rock, paper or scissors the programme should say "I don't understand, please try again" and prompt the user to enter another input, which it does, but then instead of continuing and working as intended the programme ends. Here is the code:
# The game of Rock Paper Scissors
import random
choices = ['rock', 'paper', 'scissors']
computer_choice = random.choice(choices)
selections = 'The computer chose ' + computer_choice + ' so'
computer_score = 0
user_score = 0
def choose_option():
user_choice = input('Please choose Rock, Paper or Scissors. (q to quit)\n>>> ')
while user_choice != 'q':
if user_choice in ['ROCK', 'Rock', 'rock', 'R', 'r']:
user_choice = 'rock'
elif user_choice in ['PAPER', 'Paper', 'paper', 'P', 'p']:
user_choice = 'paper'
elif user_choice in ['SCISSORS','Scissors', 'scissors', 'S', 's']:
user_choice = 'scissors'
else:
print("I don't understand, please try again.")
choose_option()
return user_choice
user_choice = choose_option()
while user_choice != 'q':
if user_choice == computer_choice:
print(selections + ' it\'s a tie')
elif (user_choice == 'rock' and computer_choice == 'scissors'):
user_score += 1
print(selections + ' you won! :)')
elif (user_choice == 'paper' and computer_choice == 'rock'):
user_score += 1
print(selections + ' you won! :)')
elif (user_choice == 'scissors' and computer_choice == 'paper'):
user_score += 1
print(selections + ' you won! :)')
elif (user_choice == 'rock' and computer_choice == 'paper'):
computer_score += 1
print(selections + ' you lost :(')
elif (user_choice == 'paper' and computer_choice == 'scissors'):
computer_score += 1
print(selections + ' you lost :(')
elif (user_choice == 'scissors' and computer_choice == 'rock'):
computer_score += 1
print(selections + ' you lost :(')
else:
break
print('You: ' + str(user_score) + " VS " + "Computer: " + str(computer_score))
computer_choice = random.choice(choices)
selections = 'The computer chose ' + computer_choice + ' so'
user_choice = choose_option()
Your problem seemed to be caused by calling the function inside the function. This solved it for me:
def choose_option():
user_choice = input('Please choose Rock, Paper or Scissors. (q to quit)\n>>> ')
while user_choice != 'q':
if user_choice in ['ROCK', 'Rock', 'rock', 'R', 'r']:
user_choice = 'rock'
return user_choice
elif user_choice in ['PAPER', 'Paper', 'paper', 'P', 'p']:
return user_choice
elif user_choice in ['SCISSORS','Scissors', 'scissors', 'S', 's']:
return user_choice
else:
while user_choice.lower() not in ["rock", "paper", "scissors", "s","r","p","q"]:
print("I don't understand, please try again.")
user_choice = input('Please choose Rock, Paper or Scissors. (q to quit)\n>>> ')
This way, if the computer does not like the input it can just request another one.
Also I would recommend using
if user_choice.lower() in [], just a little easier than typing in all the options.
Hope this helps!
instead of
else:
print("I don't understand, please try again.")
choose_option()
you can use
while user_choice != 'q':
user_choice = input('Please choose Rock, Paper or Scissors. (q to quit)\n>>> ')
if user_choice in ['ROCK', 'Rock', 'rock', 'R', 'r']:
user_choice = 'rock'
elif user_choice in ['PAPER', 'Paper', 'paper', 'P', 'p']:
user_choice = 'paper'
elif user_choice in ['SCISSORS','Scissors', 'scissors', 'S', 's']:
user_choice = 'scissors'
else:
print("I don't understand, please try again.")
continue
return user_choice
continue will cause the program to skip the rest of the loop (here, skipping the return) and continuing with the next iteration of the while loop (going back up to user_choice = ...). Also note that I think there's another bug where if user_choice is "q", the result is not actually returned.
Related
I have made a rock, paper, scissors game in python. How would I get the game to repeat over if the user enters yes? My code appears to go into a never ending loop when the user enters anything but rock, paper, or scissors
Also I'm trying to learn when and where I should use functions. If you could show a pythonic way to separate the finished code into functions I would greatly appreciate that.
import random
a = ["rock", "paper", "scissors"]
word = input('Enter rock, paper, or scissors: ')
def game():
while True:
try:
if word not in a:
raise ValueError #this will send it to the print message and back to the input option
break
except ValueError:
print(" You must enter rock, paper, or scissors.")
comp_draw = random.choice(a)
print('The computer drew ' + comp_draw)
if comp_draw == 'rock' and word=='rock':
print('It was a tie')
elif comp_draw == 'paper' and word=='paper':
print('It was a tie')
elif comp_draw == 'scissors' and word=='scissors':
print('It was a tie')
elif comp_draw == 'paper' and word=='rock':
print('you lost')
elif comp_draw == 'rock' and word=='paper':
print('you won!')
elif comp_draw == 'rock' and word=='scissors':
print('you lost')
elif comp_draw == 'scissors' and word=='rock':
print('you won!')
elif comp_draw == 'scissors' and word=='rock':
print('you won!')
elif comp_draw == 'scissors' and word=='rock':
print('you won!')
game()
play_again = input('would you like to play again: ')
Wasn't missing much, all you needed was a loop
import random
a = ["rock", "paper", "scissors"]
word = input('Enter rock, paper, or scissors: ')
def game():
while True:
try:
if word not in a:
raise ValueError #this will send it to the print message and back to the input option
break
except ValueError:
print(" You must enter rock, paper, or scissors.")
comp_draw = random.choice(a)
print('The computer drew ' + comp_draw)
if comp_draw == 'rock' and word=='rock':
print('It was a tie')
elif comp_draw == 'paper' and word=='paper':
print('It was a tie')
elif comp_draw == 'scissors' and word=='scissors':
print('It was a tie')
elif comp_draw == 'paper' and word=='rock':
print('you lost')
elif comp_draw == 'rock' and word=='paper':
print('you won!')
elif comp_draw == 'rock' and word=='scissors':
print('you lost')
elif comp_draw == 'scissors' and word=='rock':
print('you won!')
elif comp_draw == 'scissors' and word=='rock':
print('you won!')
elif comp_draw == 'scissors' and word=='rock':
print('you won!')
play_again = "yes"
while play_again == "yes":
game()
play_again = input('would you like to play again: ').lower()
Instead of :
game()
play_again = input("...")
Put your game in a loop as follow :
while True:
play_again = input ("would you like to play")
if play_again == "yes" :
game()
continue
elif play_again == "no" :
break
else:
print("answer by yes or no")
continue
There was also an issue of the variable word being outside the scope of game(). It would work on the first run but not the consequent runs thereafter. This code seems to work fine and as expected.
import random
a = ["rock", "paper", "scissors"]
def game():
while True:
try:
word = input('Enter rock, paper, or scissors: ')
if word not in a:
raise ValueError # this will send it to the print message and back to the input option
break
except ValueError:
print(" You must enter rock, paper, or scissors.")
comp_draw = random.choice(a)
print('The computer drew ' + comp_draw)
if comp_draw == 'rock' and word =='rock':
print('It was a tie')
elif comp_draw == 'paper' and word =='paper':
print('It was a tie')
elif comp_draw == 'scissors' and word =='scissors':
print('It was a tie')
elif comp_draw == 'paper' and word =='rock':
print('you lost')
elif comp_draw == 'rock' and word =='paper':
print('you won!')
elif comp_draw == 'rock' and word =='scissors':
print('you lost')
elif comp_draw == 'scissors' and word =='rock':
print('you won!')
elif comp_draw == 'scissors' and word =='rock':
print('you won!')
elif comp_draw == 'scissors' and word =='rock':
print('you won!')
if __name__ == "__main__":
game()
while True:
if input('Would you like to play_again? ') == 'yes':
game()
else:
break
I want the computer to follow a win-stay, lose-switch strategy but I can't seem to get the computer to change its option from rock. Please help!
import random
def game():
game_start
computer_count = 0
user_count = 0
while True:
base_choice = ['scissors', 'paper', 'rock']
computer_choice = 'rock'
user_choice = input('(scissors, paper, rock) Type your choice: ').strip().lower()
print()
computer_wins = 'The computer wins!'
you_win = 'You win!'
print(f'You played {user_choice}, the computer played {computer_choice}')
if user_choice == 'scissors' and computer_choice == 'rock':
computer_choice = 'rock'
elif user_choice == 'paper' and computer_choice == 'scissors':
computer_choice = 'scissors'
elif user_choice == 'rock' and computer_choice == 'paper':
computer_choice = 'paper'
print(computer_wins)
computer_count += 1
if user_choice == 'rock' and computer_choice == 'scissors':
computer_choice = 'paper'
elif user_choice == 'scissors' and computer_choice == 'paper':
computer_choice = 'rock'
elif user_choice == 'paper' and computer_choice == 'rock':
computer_choice = 'scissors'
print(you_win)
user_count += 1
else:
if user_choice == computer_choice:
print('Its a draw!')
computer_count += 0
user_count += 0
print(f'Computer: {computer_count} - You: {user_count}')
print()
game()
It's because you put computer_choice = 'rock' inside the while loop. Having inside causes it to be reset to rock for every play.
Another issue is that your if statements only prints who wins and increases count for the last one.
You can also compress the if statements a little, but that wasn't part of the question, so I didn't do it here.
game_start
computer_count = 0
user_count = 0
def game():
computer_choice = 'rock'
while True:
#base_choice = ['scissors', 'paper', 'rock']
# no point in having an unused list
user_choice = input('(scissors, paper, rock) Type your choice: ').strip().lower()
print()
computer_wins = 'The computer wins!'
you_win = 'You win!'
print(f'You played {user_choice}, the computer played {computer_choice}')
if user_choice == 'scissors' and computer_choice == 'rock':
computer_choice = 'rock'
print(computer_wins)
computer_count += 1
elif user_choice == 'paper' and computer_choice == 'scissors':
computer_choice = 'scissors'
print(computer_wins)
computer_count += 1
elif user_choice == 'rock' and computer_choice == 'paper':
computer_choice = 'paper'
print(computer_wins)
computer_count += 1
if user_choice == 'rock' and computer_choice == 'scissors':
computer_choice = 'paper'
print(you_win)
user_count += 1
elif user_choice == 'scissors' and computer_choice == 'paper':
computer_choice = 'rock'
print(you_win)
user_count += 1
elif user_choice == 'paper' and computer_choice == 'rock':
computer_choice = 'scissors'
print(you_win)
user_count += 1
else:
if user_choice == computer_choice:
print('Its a draw!')
# no point in adding 0
print(f'Computer: {computer_count} - You: {user_count}')
print()
game()
In response to your making it random comment, you need to import the random module.
Here, the base_choice is used, so uncomment it and it'll work:
import random #place at beginning of code
# can instead do `from random import choice`
base_choice = ['scissors', 'paper', 'rock']
# needs to be before you use it in random.choice
# to get random choice, do
computer_choice = random.choice(base_choice)
Instructions: Write a program to allow the user to play Rock, Paper, Scissors against the computer. The program will be menu driven (see details below). The user can continue to play the game over and over by choosing to play the game in the menu. A game consists of a single battle: win, lose, or tie. For a single battle the user makes their move and then the computer move is displayed followed by a description of who won that battle. Do not break a tie.
Once the user chooses to quit, the program then displays the win/loss/tie record for all the games just played
The user will enter the details in the following order during gameplay:
Menu choice (1 integer, 1 to play a game, 2 to quit)
Player's move (1 string, 'Rock', 'Paper', or 'Scissors')
My problem is that I'm not sure how to make the computer choose from my list and accept it. I keep getting this...1
import random
def main():
"""
Runs a game of Rock, Paper, Scissors. Asks the user for input and plays against the computer.
"""
#print display message
print('Lets play Rock, Paper, Scissors!')
moves_list = ['Rock', 'Paper', 'Scissors']
#a place to keep track of scores
tied = 0
computer = 0
player = 0
#create a variable to control loop
play_again = 1
comp_choice = process_comp()
player_choice = process_player()
winner = determine_winner(player_choice, comp_choice)
#while loop for multiple games
while play_again == 1:
comp_choice = process_comp()
player_choice = process_player()
if comp_choice == 'Rock' or comp_choice == 'rock':
print('Computer chooses rock.')
elif comp_choice == 'Paper' or comp_choice == 'paper':
print('Computer chooses paper.')
else:
print('Computer chooses scissors.')
#call the determine winner function
winner = determine_winner(player_choice, comp_choice)
#check who won the game and add 1 to the correct winner
if winner == 'computer':
computer += 1
elif winner == 'player':
player += 1
else:
tied += 1
#ask user if they want to play again
play_again = input('Would you like to play again? (Enter 1 for yes, 2 for no): ')
#display number of games that were won
print()
print('There were', tied, 'tied games.')
print('The player won', player, 'games.')
print('The computer won', computer,'games.')
#define the computer process function
def process_comp():
#make computer choose a move from list
choosen = random.choice(moves_list)
return choosen
#make sure user enters correct option.
def process_player():
player_choice = int(input('Rock, Paper, Scissors? (Enter 2 if you want to quit):'))
#if the player enters 2, quit the game
if player_choice == 2:
print('Thank you for playing!')
play_again = 2
#check if user is inputting correct selections
while player_choice != 'Rock' or player_choice != 'rock' and player_choice != 'Paper' or player_choice != 'paper' and player_choice != 'Scissors' or player_choice != 'scissors' and player_choice != 2:
print('Error! Please enter an option that was given.')
player_choice = int(input('Rock, Paper, Scissors? (Enter 2 if you want to quit):'))
return player_choice
#define the determine winner function.
def determine_winner(player_choice, comp_choice):
#setup computer selections
if comp_choice == 'Rock' or comp_choice == 'rock':
if player_choice == 'Paper' or player_choice == 'paper':
print('You win!')
winner = 'player'
elif player_choice == 'Scissors' or player_choice == 'scissors':
print('The computer wins!')
winner = 'computer'
else:
print('The game is tied. Try again.')
winner = 'tied'
if comp_choice == 'Paper' or comp_choice == 'paper':
if player_choice == 'Rock' or player_choice == 'rock':
print('The computer wins!')
winner = 'computer'
elif player_choice == 'Scissors' or player_choice == 'scissors':
print('You win!')
winner = 'player'
else:
print('The game is tied. Try again.')
winner = 'tied'
if comp_choice == 'Scissors' or comp_choice == 'scissors':
if player_choice == 'Rock' or player_choice == 'rock':
print('You win!')
winner = 'player'
elif player_choice == 'Paper' or player_choice == 'player':
print('The computer wins!')
winner = 'computer'
else:
print('The game is tied. Try again.')
winner = 'tied'
return winner
main()
You are trying to translate a string, e.g. rock into an integer (number). This is not possible as Python has no way of knowing the integer you wish to translate it into. Instead you could change your process_player() to the following. I simplified your while statement, and removed the translation to int - Then you check for whether player_choice is equal to the string '2' instead of the integer version, and it should work
def process_player():
player_choice = input('Rock, Paper, Scissors? (Enter 2 if you want to quit):')
# if the player enters 2, quit the game
if player_choice == '2':
print('Thank you for playing!')
# check if user is inputting correct selections
while player_choice.lower() not in ['rock', 'paper', 'scissors', '2']:
print('Error! Please enter an option that was given.')
player_choice = input('Rock, Paper, Scissors? (Enter 2 if you want to quit):')
return player_choice
(I am new to python, please don't judge the quality of the code right now.)
So, I am making a program which let's you play rock, papers and scissors with the code. This is my code:
import random
name = str(input("Enter your name:\n"))
choices = ["rock", "papers", "scissors"]
print(f"Hi {name}, choose between rock, papers and scissors")
while True:
user_choice = str(input('> '))
user_choice.lower()
if user_choice not in choices:
print("ERROR")
computer_choice = random.choice(choices)
print(f"Computer chooses: {computer_choice}")
if user_choice == "rock":
if computer_choice == "papers":
print("Computer wins!")
elif computer_choice == "scissors":
print(f"{name} wins!")
if user_choice == "papers":
if computer_choice == "scissors":
print("Computer wins!")
if computer_choice == "rock":
print(f"{name} wins!")
if user_choice == "scissors":
if computer_choice == "rock":
print("Computer wins!")
elif computer_choice == "papers":
print(f"{name} wins!")
if user_choice == computer_choice:
print("Tie!")
But, like when I run the code, it is working out really good. However, the problem is that if the user does not enter the correct spelling, the output looks really messed up. Like this:
Enter your name:
_____
Hi _____, choose between rock, papers and scissors
> asdf
ERROR
Computer chooses: rock
I do not want the last line, the one which says "Computer chooses: rock". Please someone suggest how do I go about this.
Thanks in advance 🙏
(EDIT: Also, if you can suggest how I can include a point system in this, which calculates how many times the computer wins, the user wins and how many times the match was a tie, the effort would be really appreciated.)
Just use continue to force the user to enter a valid choice:
while True:
user_choice = str(input('> '))
user_choice = user_choice.lower()
if user_choice not in choices:
print(f"You chose {user_choice}, please choose rock, paper, or scissors")
continue
[...]
Looks like your error problem has already been solved : )
But for the tie and score counter I have prepared the following code-
import random
name = str(input("Enter your name:\n"))
choices = ["rock", "papers", "scissors"]
print(f"Hi {name}, choose between rock, papers and scissors")
Cwin = 0
Userwin = 0
Tie = 0
while True:
user_choice = str(input('> '))
user_choice.lower()
if user_choice not in choices:
print("ERROR")
computer_choice = random.choice(choices)
print(f"Computer chooses: {computer_choice}")
if user_choice == "rock":
if computer_choice == "papers":
print("Computer wins!")
Cwin = Cwin + 1
print(int(Cwin) , "Computer victories so far")
elif computer_choice == "scissors":
print(f"{name} wins!")
Userwin = Userwin + 1
print(int(Userwin) , "User victories so far")
if user_choice == "papers":
if computer_choice == "scissors":
print("Computer wins!")
Cwin = Cwin + 1
print(int(Cwin) , "Computer victories so far")
elif computer_choice == "rock":
print(f"{name} wins!")
Userwin = Userwin + 1
print(int(Userwin) , "User victories so far")
if user_choice == "scissors":
if computer_choice == "rock":
print("Computer wins!")
Cwin = Cwin + 1
print(int(Cwin) , "Computer victories so far")
elif computer_choice == "papers":
print(f"{name} wins!")
Userwin = Userwin + 1
print(int(Userwin) , "User victories so far")
if user_choice == computer_choice:
print("Tie!")
Tie = Tie + 1
print(int(Tie) , "Ties so far")
Look here the screenshot of it working properly-
Just add computer choose inside else:
import random
name = str(input("Enter your name:\n"))
choices = ["rock", "papers", "scissors"]
print(f"Hi {name}, choose between rock, papers and scissors")
while True:
user_choice = str(input('> '))
user_choice.lower()
if user_choice not in choices:
print("ERROR")
else:
computer_choice = random.choice(choices)
print(f"Computer chooses: {computer_choice}")
if user_choice == "rock":
if computer_choice == "papers":
print("Computer wins!")
elif computer_choice == "scissors":
print(f"{name} wins!")
if user_choice == "papers":
if computer_choice == "scissors":
print("Computer wins!")
if computer_choice == "rock":
print(f"{name} wins!")
if user_choice == "scissors":
if computer_choice == "rock":
print("Computer wins!")
elif computer_choice == "papers":
print(f"{name} wins!")
if user_choice == computer_choice:
print("Tie!")
Here is a possible implementation:
import random
name = str(input("Enter your name: "))
choices = ["rock", "scissors", "paper"]
print(f"Hi {name}, choose between rock, paper and scissors")
while True:
user_choice = None
while user_choice not in choices:
user_choice = str(input('> '))
user_choice.lower()
computer_choice = random.choice(choices)
print(f"Computer chooses: {computer_choice}")
if user_choice == computer_choice:
print("Tie!")
elif choices[(choices.index(user_choice) + 1) % len(choices)] == computer_choice:
print(f"{name} wins!")
else:
print(f"Computer wins!")
Some insights:
You can accomplish the comparing mechanism with a rounded list, and not explicit comparison.
Do a while loop for the user input until it is correct.
I'm very new to Python and decided to set myself a challenge of programming a Rock, Paper, Scissors game without copying someone else's code. However, I need help from a Pythonista grown-up!
I've seen many other variations on Rock, Paper, Scissors, on here but nothing to explain why my version isn't working. My program basically follows this format: set empty variables at start, define 4 functions that prints intro text, receives player input, randomly picks the computer's choice, then assesses whether its a win or a loss for the player.
This is all then stuck in a while loop that breaks once the player selects that they don't want to play anymore. (This bit is working fine)
However, whenever I run the code, it just always gives a draw and doesn't seem to store any data for the computer's choice function call. Does anybody know what I'm doing wrong?
Many thanks!
import random
playerAnswer = ''
computerAnswer = ''
winsTotal = 0
timesPlayed = 0
def showIntroText():
print('Time to play Rock, Paper, Scissors.')
print('Type in your choice below:')
def playerChoose():
playerInput = input()
return
def computerChoose():
randomNumber = random.randint(1, 3)
if randomNumber == 1:
computerPick = 'Paper'
elif randomNumber == 2:
computerPick = 'Scissors'
else:
computerPick = 'Rock'
return
def assessResult():
if playerAnswer == computerAnswer:
print('Draw!')
elif playerAnswer == 'Rock' and computerAnswer == 'Paper':
print('Paper beats Rock. You lose!')
elif playerAnswer == 'Paper' and computerAnswer == 'Scissors':
print('Scissors cuts Paper. You lose!')
elif playerAnswer == 'Scissors' and computerAnswer == 'Rock':
print('Rock blunts Scissors. You lose!')
else:
print('You win!')
winsTotal += 1
return
while True:
timesPlayed += 1
showIntroText()
playerAnswer = playerChoose()
computerAnswer = computerChoose()
assessResult()
print('Do you want to play again? (y/n)')
playAgain = input()
if playAgain == 'n':
break
print('Thank you for playing! You played ' + str(timesPlayed) + ' games.')
You have missed returning values in most of the case.
** Add 'return playerInput ' in playerChoose() instead of only return.
** Add ' return computerPick ' in computerChoose() instead of return.
** Initialize winsTotal variable before using it as 'winsTotal = 0' in assessResult().
** Variables you have intialized at the start of program are out of scope for functions.
Please check this StackOverFlow link for understanding scope of variables in python.
** Add 'return winsTotal' in assessResult() instead of return.
import random
def showIntroText():
print('Time to play Rock, Paper, Scissors.')
print('Type in your choice below:')
def playerChoose():
playerInput = input()
return playerInput
def computerChoose():
randomNumber = random.randint(1, 3)
if randomNumber == 1:
computerPick = 'Paper'
elif randomNumber == 2:
computerPick = 'Scissors'
else:
computerPick = 'Rock'
return computerPick
def assessResult(winsTotal):
if playerAnswer == computerAnswer:
print('Draw!')
elif playerAnswer == 'Rock' and computerAnswer == 'Paper':
print('Paper beats Rock. You lose!')
elif playerAnswer == 'Paper' and computerAnswer == 'Scissors':
print('Scissors cuts Paper. You lose!')
elif playerAnswer == 'Scissors' and computerAnswer == 'Rock':
print('Rock blunts Scissors. You lose!')
else:
print('You win!')
winsTotal += 1
return winsTotal
total_win = 0
while True:
timesPlayed += 1
showIntroText()
playerAnswer = playerChoose()
computerAnswer = computerChoose()
total_win = assessResult(total_win)
print('Do you want to play again? (y/n)')
playAgain = input()
if playAgain == 'n':
break
print('Thank you for playing! You played ' + str(timesPlayed) + ' games.' + 'Out of which you won '+ str(total_win))
Output:
C:\Users\dinesh_pundkar\Desktop>python c.py
Time to play Rock, Paper, Scissors.
Type in your choice below:
"Rock"
You win!
Do you want to play again? (y/n)
"y"
Time to play Rock, Paper, Scissors.
Type in your choice below:
"Rock"
Draw!
Do you want to play again? (y/n)
"y"
Time to play Rock, Paper, Scissors.
Type in your choice below:
"Rock"
Paper beats Rock. You lose!
Do you want to play again? (y/n)
"y"
Time to play Rock, Paper, Scissors.
Type in your choice below:
"Rock"
Paper beats Rock. You lose!
Do you want to play again? (y/n)
"n"
Thank you for playing! You played 4 games.Out of which you won 1
add input and return in your functions
def computerChoose And def assessResultreturn None
for Example by this code you can play this game :
import random
playerAnswer = ''
computerAnswer = ''
winsTotal = 0
timesPlayed = 0
def playerChoose():
playerInput = input("insert:")
return playerInput
def computerChoose():
randomNumber = random.randint(1, 3)
if randomNumber == 1:
computerPick = 'Paper'
elif randomNumber == 2:
computerPick = 'Scissors'
else:
computerPick = 'Rock'
return computerPick
def assessResult(playerAnswer, computerAnswer):
if playerAnswer == computerAnswer:
print('Draw!')
elif playerAnswer == 'Rock' and computerAnswer == 'Paper':
print('Paper beats Rock. You lose!')
elif playerAnswer == 'Paper' and computerAnswer == 'Scissors':
print('Scissors cuts Paper. You lose!')
elif playerAnswer == 'Scissors' and computerAnswer == 'Rock':
print('Rock blunts Scissors. You lose!')
else:
print('You win!')
return
while True:
timesPlayed += 1
playerAnswer = playerChoose()
computerAnswer = computerChoose()
assessResult(playerAnswer,computerAnswer)
print('Do you want to play again? (y/n)')
playAgain = input()
if playAgain == 'n':
break
print('Thank you for playing! You played ' + str(timesPlayed) + ' games.')
It is always a draw because you aren't returning the answers from your function, both playerAnswer and computerAnswer return None
As some of people said playerChoose() and computerChoose() return with None
Modifidy these statement playerChoose() -> return playerInput
and computerChoose() -> return computerPick
AS well as you have to use global variable. Insert this row
global winsTotal
in the assessResult().