-1
def money():
    cashin = input("Please insert money: £1 Per Play!")
    dif = 1 - cashin
    if cashin < 1.0:
        print ("You have inserted £", cashin, " you must insert another £", math.fabs(dif))
    elif cashin > 1.0:
        print ("Please take your change: £", math.fabs(dif))
    else:
        print ("You have inserted £1")
    menu()

def menu():
    print ("Please choose an ARTIST: <enter character ID>")
    print ("<BEA> - The Beatles")
    print ("<MIC> - Michael Jackson")
    print ("<BOB> - Bob Marley")
    cid = input()
    if cid.upper == ("BEA"):
        correct = input("You have selected the Beatles, is this correct? [Y/N]:")
        if correct.upper() == ("Y"):
            bea1()
        else:
            menu()
    elif cid.upper() == ("MIC"):
        correct = input("You have selected Michael Jackson, is this correct? [Y/N]:")
        if correct.upper() == ("Y"):
            mic1()
        else:
            menu()
    elif cid.upper() == ("BOB"):
        correct = input("You have selected Bob Marley, is this correct? [Y/N]:")
        if correct.upper() == ("Y"):
            bob1()
        else:
            menu()
    else:
        print ("That is an invalid character ID")
        menu()

this is part of my code for a jukebox

my code is giving me the error that bea is not defined if I type 'bea' on the 'CHOOSE AN ARTIST' input. but i'm not trying to use it as a function or a variable? I want to use an if statement to decide what to do based on the users input

usually this works for me, I don't know what the problem is. This is only a section of my code, if you need to see more let me know

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
FluxJL
  • 19
  • 2
  • You call `bea1()`, where is this defined? – Cory Kramer Jun 30 '14 at 12:08
  • @Cyber As well as `mic1()` and `bob1()` – Unda Jun 30 '14 at 12:09
  • @Martijn: That seems like a mildly bad canonical duplicate, since it's tagged [python-3.x] (the real problem is that the OP incorrectly thinks they're using 3.x--I wonder if there's a better real duplicate that doesn't make this mistake that would make a better target. Unfortunately, most of the potential ones I've come across are already closed as dupes of that one :( ) – Wooble Jun 30 '14 at 12:12
  • @Wooble: Yeah, its not the best perhaps. If you have a better one, lets promote that one and dupe vote the rest. I went on a spree recently and only later realised I had picked the 3.x post as the canonical. – Martijn Pieters Jun 30 '14 at 12:13
  • @Wooble: still, better to find a dupe quickly then to let in the rush of answers to this *tired out* dupe. – Martijn Pieters Jun 30 '14 at 12:14
  • @Wooble: How about this one: [Problem running a Python program, error: Name 's' is not defined](http://stackoverflow.com/q/2790565). Reopen that one, vote to close others as a dupe of that one. The list is at http://stackoverflow.com/questions/linked/2612948 – Martijn Pieters Jun 30 '14 at 12:16

1 Answers1

4

In Python 2.x, to get a string from a prompt, you use raw_input() instead of input():

cid = raw_input()

The input function in Python 2 is not equivalent to input in Python 3. It does not return a string, but evaluates it. In your case, you type bea and it tries to evalueate bea as an expression. But this name is not defined.

As mentioned in the docs for input:

Equivalent to eval(raw_input(prompt)).

Also, as @frostnational notes in his comment, you forgot to actually call the upper method on the next line, so you are trying to compare the method itself with a string. You want

if cid.upper() == "BEA":
Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175