Answer to Question #308587 in Python for babu

Question #308587

question: highest investor


ramsay is a stock broker , and N people have given him money to invest in stocks. some one may invest more money in an year. To than the person who invested most with ramsay he will send a gift at the end of the year . In case of a tie he will pick the person with the smallest lexicographic name.


Note:-

  1. Name will contain alphabets and spaces
  2. Names are case insensitive(i.e Samule and samule are the same)
  3. ignore the spaces between the names

input :-


5

Harry 500

Andrew 300

Mary 1000

Jane 400

Tobey 1000


output:-

Mary 2


explanation output:- both tobey and mary have the biggest investment . as mary is smallest in lexicographic name than tobey and found at index 2 the output is "mary 2"




1
Expert's answer
2022-03-10T02:08:52-0500
num = int(input(">"))
max_invest = 0
max_name = ''
invest = []
for i in range(num):
    invest.append(input(str(i + 1)+">").split(" "))
large = int(invest[0][1])
for n, i in enumerate(invest):
    cost = int(i[1])
    if large < cost:
        max_invest = n
        max_name = i[0]
        large = cost
    elif large == cost:
        if max_name > i[0]:
            max_name = i[0]
            max_invest = n
print(max_name,' ', max_invest)

>5

1>Harry 500

2>Andrew 300

3>Mary 1000

4>Jane 400

5>Tobey 1000

Mary  2


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS