Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3312870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:02:50+00:00 2026-05-17T22:02:50+00:00

Hello everyone thanks for looking into my problem. What I am trying to do

  • 0

Hello everyone thanks for looking into my problem. What I am trying to do is write a “Structured” program in python that takes txt from a file and parses it into lists. Then after closing the file, I need to reference the user input (zipcode) in those lists and then print out the city and state according to the zipcode that they entered. My instructor is having us use structure by making several functions. I know there are probably lots of more efficient ways of doing this, but I must keep the structure thats in place.
EDIT
Here is my code(Current):

#-----------------------------------------------------------------------
# VARIABLE DEFINITIONS

eof = False
zipRecord = ""
zipFile = ""
zipCode = []
city = []
state = []
parsedList = []

#-----------------------------------------------------------------------
# CONSTANT DEFINITIONS

USERPROMPT = "\nEnter a zip code to find (Press Enter key alone to stop): "

#-----------------------------------------------------------------------
# FUNCTION DEFINITIONS

def startUp():
    global zipFile
    print "zipcode lookup program".upper()
    zipFile = open("zipcodes.txt","r")
    loadList()

def loadList():
    while readRecord():
        pass
    processRecords()


def readRecord():
    global eof, zipList, zipCode, city, state, parsedList
    zipRecord = zipFile.readline()
    if zipRecord == "":
        eof = True
    else:
        parsedList = zipRecord.split(",")
        zipCode.append(parsedList[0])
        city.append(parsedList[1])
        state.append(parsedList[2])
        eof = False
    return not eof

def processRecords():
        userInput = raw_input(USERPROMPT)
        if userInput:
            print userInput
            print zipCode
            if userInput in zipCode:
                index_ = zipcode.index(userInput) 
                print "The city is %s and the state is %s " % \
                      (city[index_], state[index_])
            else:
                print "\nThe zip code does not exist."
        else:
            print "Please enter a data"

def closeUp():
    zipFile.close()

#-----------------------------------------------------------------------
# PROGRAM'S MAIN LOGIC

startUp()
closeUp()

raw_input("\nRun complete. Press the Enter key to exit.")

Here is a sample from the zipcode txt file:

00501,HOLTSVILLE,NY

I am definitely stuck at this point and would appreciate your help in this matter.
EDIT

Thanks for all the help everyone. I really do appreciate it. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:02:51+00:00Added an answer on May 17, 2026 at 10:02 pm

    why you fill the lists zipcode, city , state like that, i mean in each user entry we get the next line from the file

    i think that you should do :

    def loadList():
        # Fill all the list first , make the readRecord() return eof (True or False).
        while readRecord():
            pass
    
        # than process data (check for zip code) this will run it only one time
        # but you can put it in a loop to repeat the action.
        processRecords()
    

    about your problem :

    def processRecords():
            userInput = raw_input(USERPROMPT)
            # Check if a user has entered a text or not
            if userInput:
                # check the index from zipcode   
    
                if userInput in zipcode:
                    # the index of the zipcode in the zipcode list is the same 
                    # to get related cities and states.
                    index_ = zipcode.index(userInput) 
                    print "The city is %s and the state is %s " % \
                          (city[index_], state[index_])
                else:
                    print "\nThe zip code does not exist."
            else:
                print "Please enter a data"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.