How Do you Fix this Program

What is happening? When the computer goes first. I get an error message saying “name ‘choice’ is not defined” on line 57 in the DEF Function “Winning”. Also when the player does first it all works…
Please help me i’m very confused… And I do have the correct indentation it’s just the computer…

#Rock, Paper, Scissors

import random

def begining():
R1 = random.randint(1,2)
if R1 == 1:
print("Player goes first ")
player()
if R1 == 2:
print("Computer goes first ")
computer()

def computer():
while True:
global comp_choice
global comp_choice_name
comp_choice = random.randint(1,3)
if comp_choice == 1:
comp_choice_name = ‘Rock’
elif comp_choice == 2:
comp_choice_name = ‘Paper’
else:
comp_choice_name = ‘Scissor’
print("I choose, " + comp_choice_name)
break
print(choice_name + " V/S " + comp_choice_name)

def player():
while True:
global choice
global choice_name
print(“Enter choice, \n”
+ “1. Rock: \n”
+ “2. Paper: \n”
+ “3. Scissor: \n”)
choice = int(input("User turn: "))
while choice > 3 or choice < 1:
choice = int(input("Enter A Valid Input: “))
if choice == 1:
choice_name = ‘Rock’
elif choice == 2:
choice_name = ‘Paper’
else:
choice_name = ‘Scissor’
print(“Player choice is: " + choice_name)
print(”\nNow it’s the Computers turn…”)
break
computer()
print(choice_name + " V/S " + comp_choice_name)

def winning():
if((choice == 1 and comp_choice == 2) or
(choice == 2 and comp_choice == 1)):
print("Paper Wins!! " , end = “”)
result = “Paper”
elif((choice == 1 and comp_choice == 3) or
(choice == 3 and comp_choice == 3)):
print("Rock Wins!! " , end = “”)
result = “Rock”
else:
print("Scissor Wins!! " , end = “”)
result = “Scissor”

print(input(‘Press Enter to start’))
begining()
winning()

1 Like

Then, shouldn’t you either not use it, or define it?
Indentation isn’t right or wrong by the way. It’s part of the code, otherwise it wouldn’t be necessary at all.

1 Like