188k views
2 votes
Considering there are 2 dictionaries, one with the name of the person and the stock name and number of stocks they have and the other dictionary has the stock name and it’s today’s market value -

Ex: a = { “Joe” :{“AAPL”:5, “AMZN”:2}, ”Bill” :{“AAPL”:2, “AMZN” :5 }}

B = {“AAPL” : 227, “AMZN” :1721 , “NFLX” : 267 , “TSLA” : 244, “FB” : 179 }



Write a Python program to find the amount of money each person makes by selling all of their stock today, and who will get the most value

User Yoshiki
by
4.8k points

1 Answer

5 votes

a = {"Joe": {"AAPL": 5, "AMZN": 2}, "Bill": {"AAPL": 2, "AMZN": 5}}

B = {"AAPL": 227, "AMZN": 1721, "NFLX": 267, "TSLA": 244, "FB": 179}

total = 0

largest = 0

for x in a:

for w in a[x]:

total += a[x][w] * B[w]

a[x] = total

if total > largest:

largest = total

print("{} will have ${}".format(x, total))

for x in a:

if a[x] == largest:

print("{} will get the most value".format(x))

I hope this helps!

User Salep
by
5.1k points