0% found this document useful (0 votes)
7 views3 pages

Aditi 1

The document contains a Python program for analyzing student marks, including functions to calculate the average score, highest and lowest scores, count of absent students, and the most frequent marks. The program prompts the user to input the number of students and their respective marks, handling absent students represented by -1. Finally, it outputs the average score, highest and lowest scores, number of absentees, and marks with the highest frequency.

Uploaded by

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

Aditi 1

The document contains a Python program for analyzing student marks, including functions to calculate the average score, highest and lowest scores, count of absent students, and the most frequent marks. The program prompts the user to input the number of students and their respective marks, handling absent students represented by -1. Finally, it outputs the average score, highest and lowest scores, number of absentees, and marks with the highest frequency.

Uploaded by

khushimarathe06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#Name=Aditi Amar Jagdale

#Roll no=SY2526CPE174
#Time=3.45 PM to 5.45 PM

def average_score(marks):
# Filter out absent students (-1)
present_marks = [m for m in marks if m != -1]
if len(present_marks) == 0:
return 0
return sum(present_marks) / len(present_marks)

def highest_lowest_score(marks):
# Filter out absent students (-1)
present_marks = [m for m in marks if m != -1]
if len(present_marks) == 0:
return None, None
return max(present_marks), min(present_marks)

def count_absent(marks):
return marks.count(-1)

def highest_frequency_mark(marks):
from collections import Counter
# Filter out absent marks
present_marks = [m for m in marks if m != -1]
if not present_marks:
return None

freq = Counter(present_marks)
# Get the mark(s) with highest frequency
max_freq = max(freq.values())
marks_with_max_freq = [mark for mark, count in freq.items() if count ==
max_freq]

# Return all marks with highest frequency (or just one)


return marks_with_max_freq, max_freq

# Main program
def main():
n = int(input("Enter number of students: "))
marks = []
print("Enter marks for each student (enter -1 if absent):")
for i in range(n):
m = int(input(f"Student {i+1}: "))
marks.append(m)

avg = average_score(marks)
high, low = highest_lowest_score(marks)
absent_count = count_absent(marks)
freq_marks, freq = highest_frequency_mark(marks)

print(f"\nAverage score of class: {avg:.2f}")


if high is not None and low is not None:
print(f"Highest score: {high}")
print(f"Lowest score: {low}")
else:
print("No students attended the test.")

print(f"Number of absent students: {absent_count}")

if freq_marks:
print(f"Mark(s) with highest frequency ({freq} times): {', '.join(map(str,
freq_marks))}")
else:
print("No marks available to calculate frequency.")

if __name__ == "__main__":
main()

You might also like