Computer Science, asked by salewrappers, 9 months ago

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". Fill in the gaps to complete this function.

Answers

Answered by niveditamishra3011
15

Answer:

def format_address(address_string):

 # Declare variables

 home_no = 0

 home_address = ' '

 parts = address_string.split()

 # Separate the address string into parts

 for part in parts:

   if part.isdigit():

     home_no = part

   else:

     home_address += part + ' '

 # Traverse through the address parts

 

   # Determine if the address part is the

   # 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(home_no, home_address)

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"

Explanation:

Answered by poojan
12

Language using: Python Programming

Program:

def format_address(address):

   x=list(address.split(' '))

   return "House number {0} on street named {1}".format(x[0],' '.join(x[1:]))

print(format_address(input("Enter the complete address: ")))

Outputs:

Input 1:

Enter the complete address: 123 Main Street

Output 1:

House number 123 on street named Main Street

Input 2:

Enter the complete address: 1001 1st Ave

Output 2:

House number 1001 on street named 1st Ave

Input 3:

Enter the complete address: 55 North Center Drive

Output 3:

House number 55 on street named North Center Drive

Learn more:

1) Printing all the palindromes formed by a palindrome word.

brainly.in/question/19151384

2) Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

brainly.in/question/15473120

Attachments:
Similar questions