Answer:
Here is a possible solution to the problem:
```python
def fix_zip_code(zip_code):
# Remove any non-digit characters
zip_code = ''.join(filter(str.isdigit, zip_code))
# Convert to 5 digits
if len(zip_code) > 5:
zip_code = zip_code[:5]
elif len(zip_code) < 5:
zip_code = zip_code.zfill(5)
return zip_code
def format_names(first_name, middle_name, last_name):
# Capitalize the first letter of each name
first_name = first_name.capitalize()
middle_name = middle_name.capitalize()
last_name = last_name.capitalize()
# Check if the total length of the names is greater than 35 characters
total_length = len(first_name) + len(middle_name) + len(last_name)
if total_length > 35:
# Remove the middle name
middle_name = ""
return first_name, middle_name, last_name
def format_address(street_address):
# Check if the length of the street address is greater than 35 characters
if len(street_address) > 35:
# Split the address into two lines
words = street_address.split()
line1 = ""
line2 = ""
current_line_length = 0
for word in words:
if current_line_length + len(word) <= 35:
# Add word to current line
line1 += word + " "
current_line_length += len(word) + 1
else:
# Add word to next line
line2 += word + " "
# Add dash to the last word on the first line
line1 = line1.rstrip().rsplit(" ", 1)
line1[1] = "-" + line1[1]
line1 = " ".join(line1)
# Remove any extra spaces
line1 = line1.strip()
line2 = line2.strip()
return line1, line2
else:
# Address fits in one line
return street_address, ""
def display_label(first_name, middle_name, last_name, address_line1, address_line2, city, state, zip_code):
print(first_name, middle_name, last_name)
print(address_line1)
print(address_line2)
print(city + ",", state + ",", zip_code)
def main():
# Get input from the user
last_name = input("Enter last name: ")
first_name = input("Enter first name: ")
middle_name = input("Enter middle name: ")
street_address = input("Enter street address: ")
city = input("Enter city: ")
state = input("Enter state: ")
zip_code = input("Enter zip code: ")
# Format the data
zip_code = fix_zip_code(zip_code)
first_name, middle_name, last_name = format_names(first_name, middle_name, last_name)
address_line1, address_line2 = format_address(street_address)
# Display the label
display_label(first_name, middle_name, last_name, address_line1, address_line2, city, state, zip_code)
# Call the main function
main()
```
This program uses the `input()` function to get the user's input for the customer information. It then calls the necessary functions to format the data and displays the formatted mailing label using the `print()` function.
You can run this program and enter the customer information from your keyboard to see the formatted mailing label.