INLAB 5

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:
include 'from pprint import pprint'
from pprint import pprint 
group1, group2 = {},{}
for i in range(6):
    name =
input().rstrip()
    experience =
int(input())
   
if i < 3:
        group1[experience] = name
   
else:
        group2[experience] = name
final_group = {}
for i in group1.keys():
    final_group[i] = group1[i]
for i in group2.keys():
    final_group[i] = group2[i]
for i in sorted(final_group.keys()):
   
del final_group[i]
   
break
chairman = max(final_group.keys())
new_mem =
input()
if new_mem in final_group.values():
   
print('Exist')
else:
   
print('Does not Exist')
pprint(final_group)
print(final_group[chairman])

Algorithm:
Step1. Initialize group1 and group2 as empty dictionaries.
Step2. Initialize i as 0 and repeat till is less than 6
Step2.1 get the name and the number of years of experience from the user
Step2.2 if i is less than 3 then let group1 key be the experience and name be the value of the key else let group2 key be the experience and name be the value of the key
Step3. Initialize final_group as an empty dictionary
Step4. Reinitialize i as the first key in group1 and repeat till i doesn’t complete all the keys in group1
Step4.1 let the value of key i of final_group be the same as the value obtained by accessing the key i of group1
Step5. Reinitialize i as the first key in group2 and repeat till i doesn’t complete all the keys in group2
Step5.2 let the value of key i of final_group be the same as the value obtained by accessing the key i of group2
Step6. Reinitialize i to be the first key of the sorted list of keys in the final_group and repeat till i doesn’t complete all the keys in the final_group
Step6.1 delete the first key and value pair in the final_group dictionary and break out from the loop
Step7. Assign chairman as the maximum value of key in final_group
Step8. Get the member that has to be searched
Step9. If the member is in the final_group display Exist else display Does not Exist
Step10. Print the final_group dictionary in sorted order.
Step11. Display the name of the chairman.

No comments:

Post a Comment

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...