SE Computer Engineering practical 5 solution

SE Computer Engineering Practical 5 solution

Question:

It is decided that weekly greetings are to be furnished to wish the students having their birthdays in that week.
The consolidated sorted list with desired categorical information is to be provided to the authority.
Write a python program to store students PRNs with date and month of birth. Let List_A and List_B be the two list for two SE Computer divisions.
Lists are sorted on date and month.
Merge these two lists into third list “List_SE_Comp_DOB” resulting in sorted information about Date of Birth of SE Computer students

Code:

from datetime import datetime

if __name__ == "__main__":
   List_A = []
   print("\nList_A:")
   n1 = int(input("\nEnter the number of students:"))
   for i in range(n1):
       tempDict = {}
       prn = input("\nEnter your PRN no. : ")
       dob = input("\nEnter your date of birth(DD-MM): ")
       tempDict['PRN'] = prn
       tempDict['DOB'] = dob
       List_A.append(tempDict)
   List_A.sort(key = lambda x: datetime.strptime(x['DOB'], '%d-%m'))
   print("\nSorted Data:")
   for item in List_A:
       print(item)

   List_B = []
   print("\nList_B:")
   n2 = int(input("\nEnter the number of students:"))
   for j in range(n2):
       tempDict = {}
       prn = input("\nEnter your PRN no. : ")
       dob = input("\nEnter your date of birth(DD-MM): ")
       tempDict['PRN'] = prn
       tempDict['DOB'] = dob
       List_B.append(tempDict)
   List_B.sort(key = lambda x: datetime.strptime(x['DOB'], '%d-%m'))
   print("\nSorted Data:")
   for item in List_B:
       print(item)

   print("\nList_SE_Comp_DOB: ")
   List_SE_Comp_DOB=List_A+List_B
   List_SE_Comp_DOB.sort(key=lambda x: datetime.strptime(x['DOB'], '%d-%m'))
   print("Sorted Data:")
   for item in List_SE_Comp_DOB:
       print(item)

Output:

Enter the number of students:3
Enter your PRN no. : 1234

Enter your date of birth(DD-MM): 12-12

Enter your PRN no. : 1245

Enter your date of birth(DD-MM): 02-09

Enter your PRN no. : 1247

Enter your date of birth(DD-MM): 09-07

Sorted Data:
{'PRN': '1247', 'DOB': '09-07'}
{'PRN': '1245', 'DOB': '02-09'}
{'PRN': '1234', 'DOB': '12-12'}

List_B:

Enter the number of students:3

Enter your PRN no. : 7890

Enter your date of birth(DD-MM): 03-09

Enter your PRN no. : 7891

Enter your date of birth(DD-MM): 14-07

Enter your PRN no. : 7892

Enter your date of birth(DD-MM): 23-05

Sorted Data:
{'PRN': '7892', 'DOB': '23-05'}
{'PRN': '7891', 'DOB': '14-07'}
{'PRN': '7890', 'DOB': '03-09'}

List_SE_Comp_DOB: 
Sorted Data:
{'PRN': '7892', 'DOB': '23-05'}
{'PRN': '1247', 'DOB': '09-07'}
{'PRN': '7891', 'DOB': '14-07'}
{'PRN': '1245', 'DOB': '02-09'}
{'PRN': '7890', 'DOB': '03-09'}
{'PRN': '1234', 'DOB': '12-12'}

Process finished with exit code 0
Tech Amplifier Final Logo