INLAB-8

INLAB-8

In FFCS students portal, the Register number, name, age, gender, address, phone number, hobby, blood group are stored. Assume that the details are present in a file named as ‘ffcs.csv’ and each field of a record are separated by a ‘,’. Write an algorithm to achieve the following and implement it using functions in Python:
a) Read and print the content of the file
b) Get a new record with the fields mentioned in order and append the file
c) Get a new record with the fields mentioned in order and append to file if the record is new and do nothing otherwise. Register number shall be used for checking if a record is new.
d) Find the number of male football players from Kerala
e) List the name and phone numbers of girls from Tamilnadu having A+ blood group
Write functions for the purpose of items (a) to (e) and call those functions defined in the order from (a) to (e).

Input Format


For items (b) and (c), read a record from the user.
Details of each student are given in the order – Register number, name, age, gender, address, phone number, hobby, blood group
No input is given for other items


Output Format


Output of item (a) – print the content of the file with each field of record separated by a comma.
Print content of file after doing operations (b) and (c), with each field of a record separated by a comma.

Program:

def read_print(): 
    ffcs = open('ffcs.csv') 
    for i in ffcs.readlines(): 
        print(i,end='') 
    ffcs.close() 
 
def append_new(): 
    temp = [] 
    ffcs = open('ffcs.csv','a') 
    for i in range(8): 
        input_text = input().rstrip() 
        temp.append(input_text) 
    temp = ','.join(temp) 
    ffcs.write('\n') 
    ffcs.write(temp) 
    ffcs.close() 
    read_print() 
 
def check_append(): 
    temp = [] 
    flag = True 
    ffcs = open('ffcs.csv','r+') 
    for i in range(8): 
        input_text = input().rstrip() 
        if i == 0 and input_text in ffcs.read(): 
            flag = False 
        temp.append(input_text) 
    temp = ','.join(temp) 
    if flag == True: 
        ffcs.write('\n') 
        ffcs.write(temp) 
    ffcs.close() 
    if flag == True: 
        read_print() 
 
def football_kerala(): 
    count = 0 
    ffcs = open('ffcs.csv') 
    for i in ffcs.readlines(): 
        if 'Kerala' in i and 'Football' in i: 
            count+=1 
    ffcs.close() 
    print('\n',count,sep='') 
 
def tamil_b_grp(): 
    ffcs = open('ffcs.csv') 
    for i in ffcs.readlines(): 
        if 'A+' in i and 'Tamilnadu' in i: 
            data = i.split(',') 
            print(data[1],data[-3],sep=' ') 
    ffcs.close() 
 
read_print() 
append_new() 
check_append() 
football_kerala() 
tamil_b_grp() 
 

Algorithm: 

Step1. define the function read_print() which reads the contents of the file and display the contents 
Step2. get the required data from the user and then append the data into ffcs.csv using the append_new 
Step3. append data that is not present in the file using check_append function 
Step4. define the function football_kerala that display people from Kerala who play Football and use the function to count and display the number people 
Step5. define tamil_b_grp that displays the name and number of students whose blood group is A+ and are from Tamilnadu 
Step6. call all the functions in the respective order. 
Step7.End  

Comments

Popular posts from this blog

MATLAB WEEK-2

PRACTICE PROBLEM 8