2
usd = 2
yen = 1000
gbp = 1.7
eur = 0.75

def again():
    choice = False
    while choice == False:
        money = input("please enter an amount ")
    try:
        int(money)
    except ValueError:
        print("inavlid: numbers only")
        choice == False
    else:
        money = int(money)
        if money >= 1000:
            confirm = input("are you sure y / n").lower()
            if confirm == "y":
                transfer()
            elif confirm == "n":
                again()
            elif confirm != "y" or choice != "n":
                print("invalid options")
                yn()
        else:
            transfer()
def xe1():
    xe = input("do you want currency rates set on this program(yes) or\ndo you want to make your own currency amounts(no)\n")
    if xe == 'yes':
        print ("you have got from ", (money), c, "to ", ((money)/c1*ac1),ac)
        quit()
    elif xe == 'no':
        er = (float(input("what is the exchange rate ")))
        print ("you have got from ", (money), c, "to ", ((money)*er), ac)
        quit()
    else:
        xe1()
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
samee
  • 21
  • 1
  • 2
    That's correct, `money` is not defined inside `xe1` or passed as a parameter to it. I suggest you read and follow a Python tutorial. – jonrsharpe Mar 11 '15 at 17:54
  • There's a good answer [here](http://stackoverflow.com/questions/291978/short-description-of-python-scoping-rules) that should help. – Celeo Mar 11 '15 at 17:56

1 Answers1

1

The variable money is indeed not defined inside the xe1, because it's scope is limited to the again() function. In a better implementation, you can pass money as a parameter for both functions, like this:

usd = 2
yen = 1000
gbp = 1.7
eur = 0.75

def again(money):
    choice = False
    while choice == False:
        money = input("please enter an amount ")
    try:
        int(money)
    except ValueError:
        print("inavlid: numbers only")
        choice == False
    else:
        money = int(money)
        if money >= 1000:
            confirm = input("are you sure y / n").lower()
            if confirm == "y":
                transfer()
            elif confirm == "n":
                again(money)
            elif confirm != "y" or choice != "n":
                print("invalid options")
                yn()
        else:
            transfer()
def xe1(money):
    xe = input("do you want currency rates set on this program(yes) or\ndo you want to make your own currency amounts(no)\n")
    if xe == 'yes':
        print ("you have got from ", (money), c, "to ", ((money)/c1*ac1),ac)
        quit()
    elif xe == 'no':
        er = (float(input("what is the exchange rate ")))
        print ("you have got from ", (money), c, "to ", ((money)*er), ac)
        quit()
    else:
        xe1(money)
Gabriel Ilharco
  • 1,649
  • 1
  • 21
  • 34