[Tutor] Fwd: You know python?

Fatima Mehak bossladyofthefuture at gmail.com
Mon Feb 21 16:04:54 EST 2022


Let me know if you know how to fix the code below to include house numbers
without generating a whole new code altogether. When I got it done it
didn't include the house numbers but included the street names only. I hope
I'm making coding sense here. Thanks.

def format_address(address_string):
# Declare variables
house_no = ""
street_no = ""
# Separate the address string into parts
sep_addr = address_string.split()
# Traverse through the address parts
for addr in sep_addr:
# Determine if the address part is the
if addr.isdigit():
house_no = addr
else:
street_no = street_no+addr
street_no = street_no + " "
# house number or part of the street name
# Does anything else need to be done
# before returning the result?
# Return the formatted string
return "house number {} on street named {}".format(house_no,street_no)
print(format_address("123 Main Street"))
# Should print: "house number 123 on street named Main Street"
print(format_address("1001 1st Ave"))
# Should print: "house number 1001 on street named 1st Ave"
print(format_address("55 North Center Drive"))
# Should print "house number 55 on street named North Center Drive"


More information about the Tutor mailing list