0% found this document useful (0 votes)
13 views2 pages

New Text Document

Uploaded by

Sandro Komunadze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

New Text Document

Uploaded by

Sandro Komunadze
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import csv ## I decided to download a cvs file from the link

class Part_1: ## This is the first class object with constructor


def __init__(self, year, district, name, facility, mark):
self.info_dict_1 = {
"SCHOOL_YEAR" : year,
"DISTRICT_NAME" : district,
"SCHOOL_NAME" : name,
"FACILITY_TYPE": facility,
"MARK_TYPE": mark
}
class Part_2: ## this is the second class object with the consturctor
def __init__(self, percent_a, percent_b, percent_c, percent_d):
self.info_dict_2 = {
"PERCENT_OF_A": percent_a,
"PERCENT_OF_B": percent_b,
"PERCENT_OF_C": percent_c,
"PERCENT_OF_D": percent_d
}

class Result(Part_1, Part_2): ## this is the chils class which inherits


from part_1 and part_2
def __init__(self, year, district, name, facility, mark, percent_a, percent_b,
percent_c, percent_d):
Part_1.__init__(self, year, district, name, facility, mark) ## calls for
part_1 consturctor
Part_2.__init__(self, percent_a, percent_b, percent_c, percent_d) ## calls
for part_2 consturctor
def print_info(self): ## this just prints the info about class object
print(f"{self.info_dict_1['SCHOOL_YEAR']} - "
f"{self.info_dict_1['DISTRICT_NAME']} - "
f"{self.info_dict_1['SCHOOL_NAME']} - "
f"{self.info_dict_1['FACILITY_TYPE']} - "
f"{self.info_dict_1['MARK_TYPE']} - "
f"{self.info_dict_2['PERCENT_OF_A']} - "
f"{self.info_dict_2['PERCENT_OF_B']} - "
f"{self.info_dict_2['PERCENT_OF_C']} - "
f"{self.info_dict_2['PERCENT_OF_D']}" )

@staticmethod ## this is the first function which gets


any argument and
def find_value_for(obj, *args): ## looks for the value of that argument
print("[")
for arg in args:
if isinstance(arg, str): ## checks if argument is surely and
string
arg = arg.upper() ## makes it uppercase because of in the
file we have like that
if arg in obj.info_dict_1: ## if its part_1's item then it
displays it
print(f"The value for {arg} is -> '{obj.info_dict_1[arg]}'")
elif arg in obj.info_dict_2: ## if its part_2's item then it
displays it
print(f"The value for {arg} is -> '{obj.info_dict_2[arg]}'")
else: ## if item is not found it prints it
print(f"The value for {arg} is not found!")
print("]\n")

students = [] ## I store students as Result objects here

with open("data.csv") as data_csv:


my_file = csv.reader(data_csv, delimiter=',') ## read file as csv
line = 0
for row in my_file:
if line == 0: ## because first line is columns names
pass

else: ## just adding students which have all grades because there is too
many
students.append(Result( ## students without the grades. By just
changing these numbers
row[0], ## it can work for all students from the list
row[4], ## just remove line == 2 etc. and write else:
row[6],
row[7],
row[14],
row[21],
row[23],
row[26],
row[29] ))
line+=1

for student in students:


## this is the first functinos which looks for a items with the names
student.find_value_for(student, "percent_of_a", "percent_of_b", "percent_of_c",
"percent_of_d")

You might also like