lundi 9 novembre 2015

python function shows--> add_charge not defined when ans is 1st not y or n

it shows error ---> add_charge referenced before assign when initial value of ans is not "y" or "n"

function choice(ans) ----> assign add_charge(additional charge) according to input user gave

def  choice(ans):
    if ans == "Y" or ans =="y" or ans == "Yes" or ans == "yes":
        add_charge = 100
    elif ans == "N" or ans =="n"or ans =="No"or ans =="no":
        add_charge = 0
    else:
        ans = f_ans() # if ans is other then y or n, ask user again and assign value
        choice(ans)

    return add_charge

Aucun commentaire:

Enregistrer un commentaire