Tuesday 5 September 2017

INLAB 5

******************************************************************************************

Q.)

Government of India has appointed two separate teams with three members each for investigating a case. After forming the two teams with three members each, as a cost-cutting measure, the government decides to merge the two teams in to a single team with five members, by eliminating the member with the least experience among all the six members from the two teams.  Use dictionaries to store the two teams and form a new team by concatenating the two teams. The chairperson of the new team is the person with the maximum experience. Design an algorithm and write the subsequent Python code to store the members  of the two teams as dictionaries, print the new (concatenated) dictionary with the names in an increasing order of experience, to check whether a given name is present in the new dictionary or not and to print the name of the chairperson of the new team.
Note: Assume that there is only one person with least experience in the two dictionaries.
Input format:
Enter the details of the first team
Name of the first member
Experience (in years) of the first member
...
....
Name of  the third member
Experience (in years) of the third member
Enter the details of the second team:
Name of the first member
Experience of the first member
....
....
Name of the third member
Experience of the third member
Enter the name to be checked in the new team
Output format:
Exists or Does not  Exist
New team with experience as key value
Name of the person who is having maximum experience
[Hint: use pprint function for printing dictionary in sorted order.
Syntax for pprint is
pprint(dictionary name)
Include the line “from pprint import pprint” in the top of your program
******************************************
Code:
from pprint import pprint
p1 = {}
s = ''
for i in range(3):
    s=input().rstrip()
    p1[s] = int(input())
p2 = {}
for i in range(3):
    s=input().rstrip()
    p2[s] = int(input())
p1.update(p2)
minx = min([i for i in p1.values()])
maxx = max([i for i in p1.values()])
for i in p1:
    if p1[i] == minx:
        del(p1[i])
        break
name = input().rstrip()
flag=0
for i in p1:
    if i == name:
        print('Exists')
        flag = 1
        break
if flag == 0:
    print('Does not Exist')
p = dict((v,k) for k,v in p1.items())
pprint(p)
for i in p1:
    if p1[i] == maxx:
        print(i)
        break
****************************************************************************
Don't confuse the { } brackets with [ ].




2 comments:

  1. copy-paste is not working!!
    what is extension name??

    ReplyDelete
    Replies
    1. select the code and drag it to the input section

      Delete