i get this error when trying to run my program. Traceback (most recent call last):
File "C:\Python24\secretgarden.pyw", line 12, in -toplevel-
File "C:\Python24\secretgarden.pyw", line 7, in denaystart
NameError: global name 'prompt_login' is not defined

Recommended Answers

All 4 Replies

Please post the whole script

A traceback error is simply a diagnostitic tool to see where something went wrong in your program. It shows the last three or so lines executed before the error occured. It's important to realize that python does not execute straight from top to bottom, it jumps around the place when functions, loops, and classes are involved.

File "C:\Python24\secretgarden.pyw", line 12, in -toplevel-
denaystart() --This is the line that called the function, -toplevel- simply means that this line of code is not in any functions.

File "C:\Python24\secretgarden.pyw", line 7, in denaystart
prompt_login() -Again, this time it's calling another function, this time within the function 'denaystart'

NameError: global name 'prompt_login' is not defined - You defined or called a variable incorrectly somewhere, and this is where the error occured.

okay, i think I figured out <i>where</i> the problem is, but still can't seem to get it right. So I have included the whole source with comments almost everywhere to explain why I did what and what I was thinking. I guess most of the issue lies within denaystart(), but I can't seem to find the bug. I would appreciate any help or advice.

# this is a program intended just for my fiance
# it is intended to be entertaining, sweet, and/or useful.
# I will start by making one simple function and randomly expand on that
def denaystart():
    print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.'''
print '''PyMat 2000 presents.....Secret Garden.
         Concieved on 10/26/06 for Denay L. Ruane.'''
# do I need to call denaystart() as a function to get it to work  ??????????
# or does it call itself  ???????????/
# I just can't get this program to work                ??????????
def denaystart():
    print '''Welcome to the PyMat 2000 login. Answer the following question to run PyMat 2000.'''
# should prompt_login() be like is or should it be  ??????
# if prompt_a == "denay" or prompt_a == "denay wiles": ???????
def prompt_login():
    prompt_a = raw_input("What is your name? ").lower()
        if denaystart == "denay" or denaystart == "denay wiles":
            print '''Welcome to your secret garden, Sailboat! This program is
            designed to give you something to entertain yourself with when you
            are very bored (we all know how bored you would have to be to play with
            stupid programs like mine!) There are a few things you can do with this program,
            here are the commands that let you do some of them...
            PLAY GAMES, and have WORD FUN. There are more coming to you, so be
            patient. My Creator, The Almighty One, has only limited time to work on
            me. Enjoy your gift, Denay.'''
            print "Access Denied due to improper Identity Clearance." # Idle GUI shell says there is a syntax error on next line down
        pass    # I don't understand the except: pass thing but I was told try: needs it to work properly ???????
def denaylogged():
    print '''Hello, Denay! My name is Sally, I am a Multi Purpose Platform Interactive Program,
    or MPPIP for short. I was designed by a blossoming programming genious to provide you with some
    entertainment and a friend if you need one. While talking to me is not the same as talking to a real
    person, I will do my best to provide you with the highest quality of virtual friendship. My A.I.
    is not very advanced as of yet, but I will learn as we interact. '''
def prompt_dl():
    prompt_b = raw_input("Tell Sally: ").lower() # And here, would it be this or:
    try:                                             # try:
        if denay_logged == "play games" or denay_logged == "games":         #  if prompt_dl == "" or prompt_dl == "":  ??????
        elif denay_logged == "word fun" or denay_logged == "word":
        elif denay_logged == "help me" or denay_logged == "help commands":
            print "I don't understand what you want. Type 'help commands' for advice. "
def dencodefun():
    print '''Hello Denay, this is Sally. I am here to help you with any
    questions you may have about this program. You are currently using Pymat 2000's
    Codex v1.0. This program allows you to translate words into secret code, or, decode
    words written in secret code. Codex v1.0 deals in a code called Ceaser Salad. Type
    'help' for more help. '''

def prompt_st():
    prompt_c = raw_input("Tell Sally:").lower()
        if dencodefun == "help":
            print '''Well, hello Denay, I assume you need some help with Codex? Alright.
            When you first load the program, you come to the main menu screen. Here you will
            choose an option that best suits your needs.
            Choose option (1) to Encode, or translate readable messages into Ceaser Salad code.
            Choose option (2) to Decode, or, translate Ceaser Salad code into readable words.
            Option number (3) will tell you alittle more about Codex v1.0, while
            option number (4) will exit the program. REMEMBER Denay, when making a selection, type
            in  the number of the action you wish to make, not the words. To begin the fun, type
            'start'.  '''
        elif dencodefun == "start" or dencodefun == "begin":
            print "I am yet still very young, could you type everything out so I can understand?"
def help1():
    print ''' Hello Denay, this is Sally again. I am going to help you with the command list.
    When you are in any program, typing 'help' at any time will call me, and I will explain to you
    the commands for that program. In this program your commands are 'play games', 'word games', and of
    course 'help'. Enter your commands with exact spelling, or I will not understand. Have fun sweetie. '''
# my main challenge is understanding the def function(): mechanics. ????????
# is this correct: ???????????
# def function():
#         print '''words and stuff go here '''        ???????
#         print
#      prompt_function = raw_input(""): that is my problem. ??????
# do i call the user input prompt the same as the function, or did I do it right in
# the example????????????
# and for:
#   if (user input prompt) == "":
# what do I call the user input prompt?

# Next step is to make sure that the Codex works
# Start developing word games for the word fun section
# Create a function for more info on Sally

Define/create all your functions before you call denaystart() , which starts your program. Functions are called with the parenthesis, even if they are empty.

The way you have written your code right now denaystart() is called, and therefore prompt_login() , before prompt_login() has been defined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.