In: Computer Science
Address Labeller Simple databases normally store address information as single line of data. In our database, fields are delimited by the percent sign '%' and can be placed in any order. Each field starts with a label "Street:", "City:", "State:", and "Zipcode:". Write an address labeller that extracts the fields from a database record entered by the user and prints a label if all fields are present. The program will report on any missing fields.
Sample runs: Enter an address database entry: State:New York%Street:12 Primrose Lane%Zipcode:11564%City:ValleyStream% 12 Primrose Lane ValleyStream, New York 11564
Enter an address database entry: Street:12 Primrose Lane%Zipcode:11564%State:New York%City:ValleyStream% 12 Primrose Lane ValleyStream, New York 11564
Enter an address database entry: Street:12 Primrose Lane%State:New York%City:ValleyStream% Error: Address does not contain zipcode
address = input('Enter an address database entry: ')
if address[-1] == '%':
    address = address[:-1]
a = address.split('%')
keys = {'State','Street','City','Zipcode'}
di = {}
new = []
for i in a:
    new.append((i.split(':')))
not_found = []
for i in new:
    k = i[0]
    v = i[-1]
    di[k] = v
flag = 1
new_set = set()
for key in di.keys():
    new_set.add(key)
for k,v in di.items():
    if v == '':
        print(f'Key {k} does not
have a value')
        exit()
      
  
if new_set == keys:
    print(f'{di["Street"]} {di["City"]},
{di["State"]} {di["Zipcode"]}')
else:
    not_in = [i for i in
list(keys.difference(new_set))]
    print(f'Error: Address does not contain', end =
' ')
    for i in not_in:
        print(i, end = ' '
)
print()