194k views
2 votes
[Exceptions, Function calling another function] Write a function ticker() that first runs (calls) read_ticker() and then stores the returned dictionary. It then runs an interactive loop with the user in which the user is prompted for a company name. If the company name (key) is in the dictionary, then its ticker form and the IPO year is printed. Otherwise a warning is printed that the company name is not in the list. If the user just hits return without entering a name, the loop stops.

this is the function that needs to be called:
def read_ticker():
d = {'1347 Capital Corp.': ('TFSCW', '2014'), '1347 Property Insurance Holdings, Inc.': ('PIH', '2014'), '1-800 FLOWERS.COM, Inc.': ('FLWS', '1999')}
return d

User ITemius
by
8.4k points

1 Answer

7 votes

def read_ticker():

d = {'1347 Capital Corp.': ('TFSCW', '2014'), '1347 Property Insurance Holdings, Inc.': ('PIH', '2014'),

'1-800 FLOWERS.COM, Inc.': ('FLWS', '1999')}

return d

def ticker():

di = read_ticker()

while True:

try:

name = input("Enter the name of a company: ")

if name == "":

return

print(di[name])

except KeyError:

print("Name not found! Please enter a valid name!")

ticker()

I hope this helps!

User ColdCat
by
7.9k points