5.5k views
1 vote
The smalled valid zip code is 00501. The largest valid zip code is 89049. A program asks the user to enter a zip code and stores it in zip as an integer. So a zip code of 07307 would be stored as 7307. This means the smallest integer value allowed in zip is 501 and the largest integer value allowed in zip is 89049. Write a while loop that looks for BAD zip code values and asks the user for another zip code in that case. The loop will continue to execute as long as the user enters bad zip codes. Once they enter a good zip code the progam will display Thank you. The first line of code that asks for the zip code is below. You don't have to write this line, only the loop that comes after it.

User Korroz
by
3.7k points

1 Answer

3 votes

Answer:

The program in Python is as follows:

zipp = int(input("Zip Code: "))

while (zipp > 89049 or zipp < 501):

print("Bad zip code")

zipp = int(input("Zip Code: "))

print("Thank you")

Step-by-step explanation:

This gets input for the zip code [The given first line is missing from the question. So I had to put mine]

zipp = int(input("Zip Code: "))

This loop is repeated until the user enters a zip code between 501 and 89049 (inclusive)

while (zipp > 89049 or zipp < 501):

This prints bad zip code

print("Bad zip code")

This gets input for another zip code

zipp = int(input("Zip Code: "))

This prints thank you when the loop is exited (i.e. when a valid zip code is entered)

print("Thank you")

User Lennox
by
3.1k points