python - I am getting a NameError: name 'n' is not defined -


this function asks name

def printname():    print("enter name: ")    n=input() printname() 

the if statement checks if n equal python

if n=="python":    print("welcome") else:    print("try again") 

n defined inside function. should work:

def printname():    print("enter name: ")    n=input()    if n=='python':      ... 

alternatively can do:

def printname():        print("enter name: ")        n=input()        return n  n = printname() # can use n 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -