0% found this document useful (0 votes)
7 views

Python BATCH 11 Voice

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

Python BATCH 11 Voice

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

PYTHON

PROGRAMMING
- PROBLEM SOLVING USING
FUNCTIONS IN PYTHON
BATCH - 11
• 231FA04467
• 231FA04453
• 231FA04443
• 231FA04421

• SUBMITTED TO : DR. PAVAN KUMAR


EXAMPLE :
I. Create a table that stores the details of student name, marks
obtained in various courses (SPE, CAL, DMS, PCP, PP). Design
and implement the following
Find the details of students who secured the first rank.
Find the details of students who repeat all the subjects.
Find the details of students who repeat in a given course
Find the details of students who got highest score in a given
course
Find the details of students who got lowest score in a given
course
Find the average score and standard deviation in a given course
Find the details of course wise absentees.
Algorithm to display the results :
• Define student data: Define a list of dictionaries, where each dictionary represents a student.
Each student dictionary contains the student's name and their marks in multiple courses.

Find first rank students:


• Initialize an empty list to store first rank students.
• Calculate the maximum total marks among all students.
• Iterate through each student:
• If the sum of the marks of the student equals the maximum total marks, add the student's name to
the list of first rank students.

Find students repeating all subjects:


• Initialize an empty list to store students repeating all subjects.
• Iterate through each student:
• Check if the set of marks in the first subject is of length 1. If it is, it means the student has the
same marks in all subjects. Add the student's name to the list of students repeating all subjects.
Find students with same marks in a particular course:
• Initialize an empty list to store students with the same marks in a particular course.
• Iterate through each student:
• Extract the marks of the particular course for each student.
• Check if the set of marks for that course is of length 1. If it is, it means the student has the same
marks in that course. Add the student's name to the list.

Find students with highest score in a course:


• Find the maximum score in the given course.
• Iterate through each student and their marks in the course:
• If the mark of the student matches the maximum score, add the student's name to the list of
students with the highest score.

Find students with lowest score in a course:


• Find the minimum score in the given course.
• Iterate through each student and their marks in the course:
• If the mark of the student matches the minimum score, add the student's name to the list of
students with the lowest score.
Calculate average and standard deviation for a course:
• Extract all scores for the given course.
• Calculate the average score by summing all scores and dividing by the total
number of scores.
• Calculate the variance by computing the average of the squared differences
between each score and the average score.
• Calculate the standard deviation as the square root of the variance.

Find absentees in a course:


• Iterate through each student:
• Check if the mark for the specified course is 0 for all marks of the student.
• If all marks for the course are 0, add the student's name to the list of absentees.

Display results:
Print the results of each operation along with appropriate labels and information.
SOURCE CODE:

students = [
{"name": "Alice", "marks": [[90, 85, 88, 92, 91], [85, 80, 82, 90, 88]]},
{"name": "Bob", "marks": [[88, 90, 87, 85, 84], [82, 85, 90, 88, 86]]},
{"name": "Charlie", "marks": [[80, 82, 85, 88, 90], [75, 80, 78, 82, 80]]}
]

def find_first_rank_students(students):
first_rank_students = []
max_total_marks = max(sum(student["marks"][0]) for student in students)
for student in students:
if sum(student["marks"][0]) == max_total_marks:
first_rank_students.append(student["name"])
return first_rank_students
max_total_marks: first_rank_students.append(student["name"])
return first_rank_students
def find_students_with_same_marks_in_all_subjects(students):
all_repeats_students = []
for student in students:
if len(set(student["marks"][0])) == 1:
all_repeats_students.append(student["name"])
return all_repeats_students

def find_students_with_same_marks_in_course(students, course_index):


repeat_students = []
for student in students:
if len(set([marks[course_index] for marks in student["marks"]])) ==
1: repeat_students.append(student["name"])
return repeat_students
def find_students_with_highest_score(students, course_index):
max_score = max([marks[course_index] for student in students for marks in
student["marks"]])
highest_score_students = [student["name"] for student in students for marks in
student["marks"] if marks[course_index] == max_score]
return highest_score_students

def find_students_with_lowest_score(students, course_index):


min_score = min([marks[course_index] for student in students for marks in
student["marks"]])
lowest_score_students = [student["name"] for student in students for marks in
student["marks"] if marks[course_index] == min_score]
return lowest_score_students
def calculate_average_and_std_deviation(students, course_index):
scores = [marks[course_index] for student in students for marks in
student["marks"]]
average_score = sum(scores) / len(scores)
variance = sum((x - average_score) ** 2 for x in scores) / len(scores)
std_deviation = variance ** 0.5
return average_score, std_deviation

def find_absentees(students, course_index):


absentees = [student["name"] for student in students if
all(marks[course_index] == 0 for marks in student["marks"])]
return absentees

course_index = 0
print("Students who secured the first rank:", find_first_rank_students(students))
print("Students who repeat all the subjects:",
find_students_with_same_marks_in_all_subjects(students))
print("Students who repeat in course", course_index + 1, ":",
find_students_with_same_marks_in_course(students, course_index))
print("Students who got the highest score in course", course_index + 1, ":",
find_students_with_highest_score(students, course_index))
print("Students who got the lowest score in course", course_index + 1, ":",
find_students_with_lowest_score(students, course_index))
average_score, std_deviation = calculate_average_and_std_deviation(students,
course_index)
print("Average score in course", course_index + 1, ":", average_score)
print("Standard deviation in course", course_index + 1, ":", std_deviation)
print("Absentees in course", course_index + 1, ":", find_absentees(students,
course_index))
OUTPUT:
THANK YOU

You might also like