-1

I have a part of a bigger program here:

from random import randint

def computerChooses():
    import random
    choices = ["rock", "paper", "scissors"]
    computerChoice = choices[randint(0,2)]




def whoWins():
    if computerChoice == "rock":
                print("DO THIS")
    elif computerChoice == "paper":
                print("DO THIS")
    elif computerChoice == "scissors":
                print("DO THIS")

computerChooses()
whoWins()

I always end up with:

NameError: name 'computerChoice' is not defined

(even though I believe it is!)

This, the error message states, is for line 20, and line 12.

What did I do wrong and where, specifically?

Thanks, Khy

KhyCoder
  • 3
  • 1
  • 1
    Make computerChoice a global variable. Add 'global computerChoice' in the beginning of the function computerChooses(). – Sheikh Arbaz Dec 26 '18 at 10:40

1 Answers1

-1
from random import randint

def computerChooses():
    import random
    choices = ["rock", "paper", "scissors"]
    computerChoice = choices[randint(0,2)]

    return computerChoice




def whoWins(computerChoice):
    if computerChoice == "rock":
            print("DO THIS")
    elif computerChoice == "paper":
            print("DO THIS")
    elif computerChoice == "scissors":
            print("DO THIS")

result = computerChooses()
whoWins(result)
Ali.Turkkan
  • 266
  • 2
  • 11