Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
chatbot-final/student_report.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (39 sloc)
1.41 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_file(): | |
''' | |
read csv file form disk | |
and parse into the individual student | |
into dictionary form | |
''' | |
file = open("student.csv") | |
lines = file.readlines() | |
# print(lines) | |
# get headers from line 1 and strip \n | |
header = list(map(lambda x:x.strip(), lines[0].split(","))) | |
students = [] | |
for student in lines[1:]: | |
# get student individual data and strip \n characters | |
data = map(lambda x:x.strip(), student.split(",")) | |
students.append(dict(zip(header, data))) | |
return students | |
def calculate_total_marks(students): | |
st = [] | |
for s in students: | |
total = int(s["nepali"])+ int(s["english"])+int(s["math"])+int(s["science"])+int(s["social"]) | |
s["total"] = total | |
st.append(s) | |
# print("Total marks for", s["name"], "is", total) | |
return st | |
def get_passed_student(students): | |
return list(filter(lambda x:int(x["math"])>40 and int(x["science"])>40 , students)) | |
def get_merit_list(students): | |
return sorted(students, key=lambda x:x["total"], reverse=True) | |
def main(): | |
students = read_file() | |
# print(students) | |
student_passed = get_passed_student(students) | |
students_with_total = calculate_total_marks(student_passed) | |
# print(students_with_total) | |
merit_list = get_merit_list(students_with_total) | |
print(merit_list) | |
if __name__ == '__main__': | |
main() |