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:
            temp = i.split(',')
            if temp[3] == 'M':
                count+=1
    ffcs.close()
    print(count,sep='')

def tamil_b_grp():
    ffcs = open('ffcs.csv')
    for i in ffcs.readlines():
        if 'A+' in i and 'Tamilnadu' in i:
            temp = i.split(',')
            if temp[3] == 'F':
                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    

    



10 comments:

  1. bro this solution is not working

    ReplyDelete
    Replies
    1. updated the code..just a minor change...thnx for pointing out

      Delete
  2. Replies
    1. Updated the code bro...should definitely work now

      Delete
  3. in question it is asked to list out only male football players and list out names of only girls from TN who are having 'A+' .

    ReplyDelete
    Replies
    1. Thanks for pointing out....corrected that in the update

      Delete
  4. Bro how did you create that initial file

    ReplyDelete
    Replies
    1. Can you share the link with us so we can run the program in our laptops and check it

      Delete
    2. I found the link as a comment on my post ONE HELP GUYS...check the comments section in that page and you will find the link

      Delete

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...