How to create a Rock, Paper, Scissors program - python

I'm very new to python and am taking an online class. I'm not very familiar with many functions in python so if you could keep it somewhat basic for me to keep track of, I would really appreciate it. I am trying to make a program that runs Rock, Paper, Scissors with a user but the num_games is not being accepted in the "for i in range". Also, I have run it and found that Scissors can beat Rock (THIS IS ANARCHY!). Can anyone assist me? Thanks in advance!
import random
def comp_turn():
comp_move = random.randint(1,3)
if comp_move == 1:
return "Rock!"
elif comp_move == 2:
return "Paper!"
else:
return "Scissors!"
def main():
num_games = int(input("Enter how many games you would like to play: "))
print "You are going to play " + str(num_games) + " games! Here we go!"
num_wins = 0
for i in range(num_games):
user_move = input("Choose either Rock, Paper or Scissors and enter it: ")
cpu_turn = comp_turn()
print "The computer went with: " + cpu_turn
if user_move == 'Rock' and cpu_turn == 'Scissors':
print "You won! Nice job!"
num_wins +=1
elif user_move == 'Paper' and cpu_turn == 'Rock':
print "You won! Nice job!"
num_wins +=1
elif user_move == 'Scissors' and cpu_turn == 'Paper':
print "You won! Nice job!"
num_wins +=1
elif user_move == cpu_turn:
print "Oh! You tied"
else:
print "Whoops! You lost!"
return num_wins
print main()

This should be what you want:
import random
def comp_turn():
return random.choice(['Rock','Paper','Scissors'])
def main():
num_games = int(input("Enter how many games you would like to play: "))
print("You are going to play " + str(num_games) + " games! Here we go!")
num_wins = 0
for i in range(num_games):
user_move = input("Choose either Rock, Paper or Scissors and enter it: ")
cpu_turn = comp_turn()
print("The computer went with: " + cpu_turn)
if user_move == 'Rock' and cpu_turn == 'Scissors': print("You won! Nice job!"); num_wins +=1
elif user_move == 'Paper' and cpu_turn == 'Rock': print("You won! Nice job!"); num_wins +=1
elif user_move == 'Scissors' and cpu_turn == 'Paper': print("You won! Nice job!"); num_wins +=1
elif user_move == cpu_turn: print("Oh! You tied")
else: print("Whoops! You lost!");
return num_wins
print(main())
Or even Better:
import random
def comp_turn():
return random.choice(['Rock','Paper','Scissors'])
def main():
num_games = int(input("Enter how many games you would like to play: "))
print("You are going to play " + str(num_games) + " games! Here we go!")
num_wins = 0
winning=[('Rock','Scissors'),('Paper','Rock'),('Scissors','Paper')]
for i in range(num_games):
user_move = input("Choose either Rock, Paper or Scissors and enter it: ")
cpu_turn = comp_turn()
print("The computer went with: " + cpu_turn)
if (user_move,cpu_turn) in winning:
print('You won!')
num_wins+=1
elif user_move == cpu_turn:
print('Same')
else:
print('You lost!')
return num_wins
print(main())
And another option that's also good:
import random
def comp_turn():
return random.choice(['Rock','Paper','Scissors'])
def main():
num_games = int(input("Enter how many games you would like to play: "))
print("You are going to play " + str(num_games) + " games! Here we go!")
num_wins = 0
d={}.fromkeys([('Rock','Scissors'),('Paper','Rock'),('Scissors','Paper')],'You Won')
for i in range(num_games):
user_move = input("Choose either Rock, Paper or Scissors and enter it: ")
cpu_turn = comp_turn()
print("The computer went with: " + cpu_turn)
if not user_move == cpu_turn:
print(d.get((user_move,cpu_turn),'You lost!'))
else:
print('Same')
return num_wins
print(main())

Here's what you want:
import random
outcome = random.choice(['Rock', 'Paper', 'Scissors'])
print(outcome)

Have you tried removing the '!' in the comp_turn function? It seems like cpu_turn variable will contain either 'Rock!', 'Scissors!' or 'Paper!' while your if-else condition is looking for either 'Rock', 'Scissors' or 'Paper' without the '!'. So, no matter what the player or cpu chooses, it will go into 'else' in the 'for' loop and the player loses.
This is the edited code:
import random
def comp_turn():
comp_move = random.randint(1,3)
if comp_move == 1: return "Rock"
elif comp_move == 2: return "Paper"
else: return "Scissors"
def main():
num_games = int(input("Enter how many games you would like to play: "))
print("You are going to play " + str(num_games) + " games! Here we go!")
num_wins = 0
for i in range(num_games):
user_move = input("Choose either Rock, Paper or Scissors and enter it: ")
cpu_turn = comp_turn()
print("The computer went with: " + cpu_turn)
if user_move == 'Rock' and cpu_turn == 'Scissors':
print("You won! Nice job!")
num_wins +=1
elif user_move == 'Paper' and cpu_turn == 'Rock':
print("You won! Nice job!")
num_wins +=1
elif user_move == 'Scissors' and cpu_turn == 'Paper':
print("You won! Nice job!")
num_wins +=1
elif user_move == cpu_turn:
print("Oh! You tied")
else: print("Whoops! You lost!")
return num_wins
print(main())
Do note that the player's input is case sensitive too. Hope this helps!

Related

The terminal says that computer_choice doesn’t exist even though it does

WHile I was attempting a simple rock, paper scissors, I ran into this proble. When I execute the file and input the user_input, it says to me that the variable computer_choice doesn’t exist, even though it does exist. I would appreciate if someone could help me, thank you.
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)
computer_choice = options[random_number]
print ("The computer picked:", computer_choice + ".")
if user_input == "rock" and computer_choice == "scissors" :
print("You Won!")
user_wins += 1
continue
elif user_input == "scissors" and computer_choice == "paper" :
print("You Won!")
user_wins += 1
continue
elif user_input == "paper" and computer_pick == "rock" :
print("You Won!")
user_wins += 1
continue
else:
print("You Lost!")
computer_wins += 1
continue
print("You won", user_wins,"times and the computer won", computer_wins, "times.")
print("Goodbye")
You have to be careful with indentation when using python:
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
# not at this level
# at this level
random_number = random.randint(0, 2)
computer_choice = options[random_number]
print("The computer picked:", computer_choice + ".")
if user_input == "rock" and computer_choice == "scissors":
print("You Won!")
user_wins += 1
continue
elif user_input == "scissors" and computer_choice == "paper":
print("You Won!")
user_wins += 1
continue
elif user_input == "paper" and computer_choice == "rock": #not computer_pick
print("You Won!")
user_wins += 1
continue
Also you wrote computer_pick in line 31, probably you mean computer_choice

Print wont print after elif statment [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
So I am trying to make a cowboy game (double 07) in python. I have the first elif statement working just fine but the other two aren't working. There are more to come but I want to sort the errors out so I don't continue doing them.
import sys
import os
import time
import random
import colorama
from colorama import Fore
import random
#cool typing effect
from sys import stdout as s
from time import sleep as j
def w(print):
for i in print:
j(.03)
s.write(i)
s.flush()
next = input()
def noinput(print):
for i in print:
j(.03)
s.write(i)
s.flush()
#main code for the game hub
def guess_the_number():
os.system('clear')
num = random.randint(1, 50)
guess = "none"
while guess != num:
guess = input(Fore.CYAN + "Choose a number: ")
guess = int(guess)
if guess == num:
w(Fore.GREEN + "You guessed the correct number!")
os.system('clear')
else:
w(Fore.RED + "Sorry try again")
print(Fore.WHITE + "------------")
if guess > num:
w("your number is too large")
os.system('clear')
else:
w("your number is too small")
os.system('clear')
def rock_paper_scissors():
os.system('clear')
user_action = input(Fore.BLUE + "Pick your item (rock, paper, scissors): ")
w(Fore.WHITE + "you chose: " + user_action)
computer_choice = ["scissors", "paper", "rock"]
computer_choice = random.choice(computer_choice)
w(Fore.WHITE + "computer chose: " + computer_choice)
if user_action == computer_choice:
w(Fore.BLUE + f"Both players chose {user_action} its a tie!")
elif user_action == "rock":
if computer_choice == "scissors":
w(Fore.GREEN + "Player wins! Rock destroys Scissors.")
else:
w(Fore.RED + "Paper covers Rock! Computer wins.")
elif user_action == "paper":
if computer_choice == "rock":
w(Fore.GREEN + "Player wins! Paper covers Rock.")
else:
w(Fore.RED + "Scissors cut Paper! Computer wins.")
elif user_action == "scissors":
if computer_choice == "paper":
w(Fore.GREEN + "Player wins! Scissors cut Paper.")
else:
w(Fore.RED + "Rock destroys Scissors! Computer wins.")
os.system('clear')
play_again = input(Fore.CYAN + "Play again? y/n: ")
if play_again == ("y"):
os.system('clear')
rock_paper_scissors()
else:
os.system('clear')
choices()
The error is in this game
def cowboy_game():
os.system('clear')
#----cowboy game code-------
user_action = input("pick your move: ")
os.system('clear')
computer_choice = ["shoot", "reload", "guard"]
computer_choice = random.choice(computer_choice)
w("player chose: " + str(user_action))
w("computer chose: " + str(computer_choice))
#random if statement so elif will work since python is retarded in that way
fgf = print("")
if fgf == ("f"):
print("")
elif user_action == "shoot":
if computer_choice == "shoot":
print(Fore.WHITE + "Both Players killed each other. ")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
It prints the statement above
elif user_action == "shoot":
if computer_choice == "reload":
print(Fore.WHITE + "Player killed enemy.")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
elif user_action == "shoot":
if computer_choice == "guard":
print(Fore.WHITE + "Enemy blocked the bullet. No damage.")
cowboy_game()
os.system('clear')
It doesn't print at all for those statments
w(Fore.WHITE + "Welcome to my game hub! Pick a number to start ")
os.system('clear')
print("----------")
def choices():
print(Fore.CYAN + "1) Rock Paper Scissors")
print(Fore.WHITE + "----------")
print(Fore.CYAN + "2) Guess the number")
print(Fore.WHITE + "----------")
print(Fore.CYAN + "3) Cowboy game")
print(Fore.WHITE + "---------")
choices()
choice = input("Choice: ")
if choice == ('1'):
os.system('clear')
w("Everyone knows how to play this. Have fun!")
rock_paper_scissors()
if choice == ('2'):
os.system('clear')
w("Welcome to Guess the Number! Try and guess the number to play")
guess_the_number()
if choice == ('3'):
os.system('clear')
w("--(Welcome to cowboy! Instructions in the next line)--")
os.system('clear')
w("To shoot you need to reload first. choices: reload, guard, or shoot. What these do
are self explanatory lol")
w(Fore.CYAN + "press enter to start the game")
os.system('clear')
w(Fore.BLUE + "have fun! :)")
os.system('clear')
cowboy_game()
I cannot find anything online to help with this so I'm going to leave it up to the users on this site.
Your conditions for the Elif statements are the same.
try:
elif user_action == "shoot":
if computer_choice == "shoot":
print(Fore.WHITE + "Both Players killed each other. ")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
elif computer_choice == "reload":
print(Fore.WHITE + "Player killed enemy.")
time.sleep(0.5)
play_again = input("Play again? y/n: ")
if play_again == ("y"):
cowboy_game()
os.system('clear')
if play_again == ("n"):
choices()
os.system('clear')
elif computer_choice == "guard":
print(Fore.WHITE + "Enemy blocked the bullet. No damage.")
cowboy_game()
os.system('clear')
elif user_action == "reload":
(rest of your edge cases)

my rock paper scissors gives me nothing in output (python)

I am new to python and as a practice I'm trying to write a rock paper scissors with it.
I triple checked eth but i can't find the problem.
I'm using visual studio code console. the msvcrt is for "getch" and I'm not sure about about the random function syntax
problem: when you give it the input number, It doesn't do or write anything despite the program.
help me pleaaaaase.
import random
import msvcrt
##################################################
player_move = " "
system_move = " "
##################################################
def rand(system_move):
rn = random.randint(1, 3)
if rn == 1:
system_move = "Rock"
elif rn == 2:
system_move = "Paper"
elif rn == 3:
system_move = "Scissors"
else:
rand()
return system_move
##################################################
print("!!! Rock, Paper, Scissors !!!\n\n\n")
###################################################
def playermove(player_move):
print("What do you want to go with?\n1-Rock\n2-paper\n3-scissors\n")
temp = msvcrt.getch()
if temp == '1' or 1:
player_move = 'Rock'
elif temp == '2' or 2:
player_move = 'Paper'
elif temp == '3' or 3:
player_move = 'Scissors'
else:
print(f"invalid input {player_move}. Try again\n")
playermove()
return player_move
###################################################
pm = ' '
sm = ' '
rand(sm)
playermove(pm)
if pm== 'Scissors':
if sm == "Scissors":
print(f"System move: {sm}\nIt's a tie!\n")
elif sm == "Rock":
print(f"System move: {sm}\nSystem won!\n")
elif sm == "Paper":
print(f"System move: {sm}\nYou won!\n")
else:
print("Oops! Something went wrong.\n")
elif pm == "Paper":
if sm == "Scissors":
print(f"System move: {sm}\nSystem won!\n")
elif sm == "Rock":
print(f"System move: {sm}\nYou won!\n")
elif sm == "Paper":
print(f"System move: {sm}\nIt's a tie!\n")
else:
print("Oops! Something went wrong.\n")
elif pm == "Rock":
if sm == "Scissors":
print(f"System move: {sm}\nYou won!\n")
elif sm == "Rock":
print(f"System move: {sm}\nIt's a tie!\n")
elif sm == "Paper":
print(f"System move: {sm}\nSystem won!\n")
else:
print("Oops! Something went wrong.\n")
print("Press any key to exit...")
xyz = msvcrt.getch()
Well, the reason your code doesn't work is because you are not assigning the return value of your functions to any variable. To fix your code you need to do the following:
sm = rand(sm)
pm = playermove(pm)
In Python, passing an immutable object like string means that you cannot make any changes to it. As you're not using the passed value, your function's signature should actually look like this.
def rand()
def playermove()
After you do this, you'll see there are other things you need to fix in your code.
Try this code. Just replace snake, water, gun by rock, paper, scissors.
print(" \t\t\t Welecome to Snake , Water , Gun game\n\n")
import random
attempts= 1
your_point=0
computer_point=0
while (attempts<=10):
lst=["snake","water","gun"]
ran=random.choice(lst)
print("what do you choose snake, water or gun")
inp=input()
if inp==ran:
print("tie")
print(f"you choosed {inp} and computer guess is {ran}")
print("No body gets point\n")
elif inp=="snake" and ran=="water":
your_point=your_point+1
print(f"you choosed {inp} and computer guess is {ran}")
print("The snake drank water\n")
print("You won this round")
print("you get 1 point\n")
elif inp=="water" and ran=="snake":
computer_point = computer_point + 1
print(f"you choosed {inp} and computer guess is {ran}")
print("The snake drank water\n")
print("You Lost this round")
print("computer gets 1 point\n")
elif inp=="water" and ran=="gun":
print(f"you choosed {inp} and computer guess is {ran}")
your_point = your_point + 1
print("The gun sank in water\n")
print("You won this round")
print("you get 1 point\n")
elif inp == "gun" and ran == "water":
print(f"you choosed {inp} and computer guess is {ran}")
computer_point = computer_point + 1
print("The gun sank in water\n")
print("You Lost this round")
print("computer gets 1 point\n")
elif inp == "gun" and ran == "snake":
print(f"you choosed {inp} and computer guess is {ran}")
your_point = your_point + 1
print("The snake was shoot and he died\n")
print("You Won this round")
print("you get 1 point\n")
elif inp == "snake" and ran == "gun":
print(f"you choosed {inp} and computer guess is {ran}")
computer_point=computer_point+1
print("The snake was shoot and he died\n")
print("You Lost this round")
print("computer gets 1 point\n")
else:
print("invalid")
print(10 - attempts, "no. of guesses left")
attempts = attempts + 1
if attempts>10:
print("game over")
if computer_point > your_point:
print("Computer wins and you loose")
if computer_point < your_point:
print("you win and computer loose")
print(f"your point is {your_point} and computer point is {computer_point}")

rock paper scissor python program input error

import random
def rpc():
a = ["rock", "paper", "scissor"]
b = random.choice(a)
print(b)
userinput = input('please type rock, paper or scissor:')
if userinput == "":
print("please print the right thing")
rpc()
if userinput != "rock":
print("type the right thing!")
rpc()
if userinput != "paper":
print("type the right thing!")
rpc()
if userinput != "scissor":
print("type the right thing!")
rpc()
while b == userinput:
print("it is a draw, do you want to play another one?")
c = input("type 'y' if you want to play one more time or press 'n': ")
if c == 'y':
rpc()
elif c =='n':
break
else:
print("print the right words please")
if b == 'rock' and userinput == 'paper':
print("you win!")
rpc()
elif b == 'rock' and userinput == 'scissor':
print("you lost")
rpc()
elif b == 'paper' and userinput == 'scissor':
print("you win!")
rpc()
elif b == 'paper' and userinput == 'rock':
print("you lost!")
rpc()
elif b == 'scissor' and userinput == 'rock':
print("you win!")
rpc()
elif b == 'scissor' and userinput == 'paper':
print("you lost!")
rpc()
rpc()
This is my code for rock paper and scissor, it's pretty simple but when I run my code and input my rock, paper and scissor, I get my please print the right thing statement, O have no idea why it's happening, any help would be wonderful, thank you!
Lets clean this up....
userinput = input('please type rock, paper or scissor:')
while userinput not in acceptable_inputs:
userinput = input('please type rock, paper or scissor:')
opponents_choice = random.choice(objects)
# Check and print. Loop to keep playing - 2 out of 3 wins....
import random
def winner(riya,siya):
if (riya==siya):
return None
elif (riya=="s"):
if (siya=="p"):
return False
elif(siya=="k"):
return True
elif (riya=="p"):
if (siya=="s"):
return False
elif (siya=="k"):
return True
elif (riya=="k"):
if (siya=="s"):
return True
elif (siya=="p"):
return False
print("riya pick: stone(s) paper(p) sessior(k)")
a= random.randint(1,3)
if a==1:
riya="s"
elif a==2:
riya="p"
elif a==3:
riya="k"
siya=input(" siya pick: stone(s) paper(p) sessior(k)")
b=winner(riya,siya)
print(f"riya pick{riya}")
print(f"siya pick {siya}")
if b==None:
print("tie")
elif b:
print("winner")`enter code here`
else:enter code here
print("loose")

Python Newbie - Rock, Paper, Scissors

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().

Categories