Residents’ Information

Residents’ Information

Mr. Joe wants to collect the details of Central Government employees in his locality  – that includes their name, age, designation, and band. He wants to view this information as a whole and also with respect to bands.

Write a Python program to accomplish the same. Create a list of tuples  with the name  ‘List_of_Residents’  to store the information obtained from the residents. Use insert() to insert tuples into this list. Observe the sample input and output and code accordingly.

Note:
1. If the age provided is not between 21 and 58, display ‘Invalid”  and stop the program.
2.If the band entered by the user or  the interested band entered by the user is not A,B,C or D, display ‘Invalid” and stop the program.
3. If the valid band asked for is absent in the list of resident – details created, ‘No resident under this band’4. If the no. of residents provided is not equal to or above zero, display ‘Invalid” and stop the program.
Sample Input 1:
No of Residents : 5

Resident 1:
Name : Mr. Ram
Age : 30
Designation : Commissioned Officer – IAF
Band : A

Resident 2:
Name : Mr. Raj
Age : 35
Designation :  Inspector of Income Tax
Band : B

Resident 3:
Name : Mr. Alex
Age : 40
Designation : Central Excise Inspector
Band : B

Resident 4:
Name : Mr. Joe
Age : 45
Designation : Stenographer
Band : C

Resident 5:
Name : Mr. Ali
Age : 42
Designation : Peon
Band : D

Sample Output 1:
(‘NAME’, ‘AGE’, ‘DESIGNATION’, ‘BAND’)
(‘Mr. Ram’, 30, ‘Commissioned Officer – IAF’, ‘A’)
(‘Mr. Raj’, 35, ‘Inspector of Income Tax’, ‘B’)
(‘Mr. Alex’, 40, ‘Central Excise Inspector’, ‘B’)
(‘Mr. Joe’, 45, ‘Stenographer’, ‘C’)
(‘Mr. Ali’, 42, ‘Peon’, ‘D’)

Enter your band of interest : B
(‘NAME’, ‘AGE’, ‘DESIGNATION’, ‘BAND’)
(‘Mr. Raj, 35, ‘Inspector of Income Tax’, ‘B’)
(‘Mr. Alex, 40, ‘Central Excise Inspector’, ‘B’)
Sample Input 2:No of Residents :2

Resident 1:
Name :David
Age :23
Designation :PRO
Band :A

Resident 2:
Name :Raj
Age :34
Designation :RMO
Band :C
Sample Output 2:
(‘NAME’,’AGE’,’DESIGNATION’,’BAND’)
(‘David’, 23, ‘PRO’, ‘A’)
(‘Raj’, 34, ‘RMO’, ‘C’)

Enter your band of interest :B(‘NAME’, ‘AGE’, ‘DESIGNATION’, ‘BAND’)
No resident under this band

Code :-

list_of_tuples=[]
tup=()
n=int(input("No of Residents : "))
if n>0:
    list_of_tuples.append(('NAME','AGE','DESIGNATION','BAND'))
    for i in range(n):
        tup=()
        print("Resident "+str(i+1)+":")
        name=input("Name : ")
        age=int(input("Age : "))
        if age<21 or age>58:
            print("Invalid")
            exit()
        designation=input("Designation : ")
        band=input("Band : ")
        if band not in ('A','B','C','D'):
            print("Invalid")
            exit()
        print()
        tup=tup+(name,age,designation,band)
        list_of_tuples.append(tup)
        del tup
    for i in list_of_tuples:
        print(i)
    bn=input("\nEnter your band of interest : ")
    if bn not in ('A','B','C','D'):
        print("Invalid")
        exit()
    res=[sub for sub in list_of_tuples if (sub[3]==bn)]
    print(list_of_tuples[0])
    if not res:
        print("No resident under this band")
    else:
        for i in res:
            print(i)
    
else:
    print("Invalid")

Leave a Comment

Your email address will not be published. Required fields are marked *

x