On 13/10/15 00:32, Nym City wrote:

ans=raw_input("What would you like to do? ")
    if ans=="1":
      locality = raw_input("\nEnter City ")
      break
    elif ans=="2":
        region = raw_input("\n Search by State ")
        break
    elif ans=="3":
        zip = raw_input("\n Search by Zip ")
        break
    elif ans=="4":
      print("\n Goodbye")
      break
... The use case is that by not knowing which of the 4 options the user will select,


But you know what they select after they have done it so you need to wait
till that point to run the appropriate query. And ans tells you which choice
the user made.

NameError: name 'locality' is not defined

--------
The error points back to where this is:

varibles = [locu_search(locality), region_search(region), zip_search(zip)]

I don't understand why Python thinks that locality (and others) are not defined when I defined them at the very beginning.


You didn't. You only define them once the user makes a choice.
eg. If the ans is 3 then locality and region are not defined.

But even if they were (with default values) you don;t want to
run all the queries each time. Only run the query selected by the user.
So call the query functions in the if/else structure where you set the variables.


HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to