227k views
1 vote
Write a program named CheckZips that is used by a package delivery service to check delivery areas. The program contains an array that holds the 10 zip codes of areas to which the company makes deliveries. Prompt a user to enter a zip code, and display a message indicating whether the zip code is in the company’s delivery area.

User Zetlen
by
3.9k points

1 Answer

3 votes

Answer:

# list of 10 zip codes assigned to zip

zips = ["12789", "54012", "54481", "54982", "60007", "60103", "60187", "60188", "71244", "90210"]

# user is prompt to enter zip code and assigned to user_zip

user_zip = input("Enter your zip code: ")

# if else statement to check if user input is available for delivery

# if statement check if user zip is in zip, if it is, it display

# delivery is okay to specified zip

if user_zip in zips:

print("Delivery to {} ok.".format(user_zip))

# else it display no delivery to such zip code

else:

print("Sorry - no delivery to {}.".format(user_zip))

Step-by-step explanation:

The question doesn't specify programming language to use. Since no programming language was stated, the problem was solved using Python3. List structure is the equivalent of array in Python.

Assumption was also made on the array holding 10 zip codes of areas to which the company make deliveries.

The program first initialized a list of 10 zip codes and assigned it to zips. Then it prompt the user to enter a zip code which is assigned to user_zip.

Then if-else statement is used to check if user inputted zip is available with the zips variable.

If it is available, "Delivery ok" is displayed to the user else "no delivery" is displayed to the user.

User Jkeesh
by
3.9k points