[Tutor] getting unknown results
shubham sinha
upwkwd at gmail.com
Fri Apr 24 03:52:39 EDT 2020
Hi,
my question:
The format_address function separates out parts of the address string into
new strings: house_number and street_name, and returns: "house number X on
street named Y".
The format of the input string is: numeric house number, followed by the
street name which may contain numbers, but never by themselves, and could
be several words long.
For example, "123 Main Street", "1001 1st Ave", or "55 North Center Drive".
my code:
def format_address(address_string):
# Declare variables
number = []
place = []
# Separate the address string into parts
split_string = address_string.split()
# Traverse through the address parts
for i in range(0, len(split_string)):
# Determine if the address part is the
# house number or part of the street name
if split_string[i].isnumeric():
# Does anything else need to be done
# before returning the result?
number.append(split_string[i])
return place.append(split_string[i])
# Return the formatted string
place = " ".join(place)
return "house number {number} on street named {place}".format(number
,place = " ".join(place) )
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"
my output:
None
None
None
I am getting result "none" instead of expected result.
Please help me through this.
Thanks,
Shubham K Sinha
More information about the Tutor
mailing list