Soru
Use a function to calculate the average marks. Use another function to find the highest mark and the lowest mark Use a function to count how many students scored above average. 3. Output: Print all the marks , the average mark, the highest mark, the lowest mark, and the number of students scoring above average.
Çözüm
4.4
(368 Oylar)
Esra
Kıdemli · 10 yıl öğretmeni
Uzman doğrulaması
Cevap
To calculate the average marks, you can use the following functionpythondef calculate_average_marks(marks): return functions:```pythondef find_highest_mark(marks): return max(marks)def find_lowest_mark(marks): return min(marks)```To count how many students scored above average, you can use the following function:```pythondef count_students_above_average(marks, average_marks): return sum(1 for mark in marks if mark > average_marks)```Finally, to output all the marks, the average mark, the highest mark, the lowest mark, and the number of students scoring above average, you can use the following code:```pythonmarks = [85, 90, 78, 92, 88] # Example marks listaverage_marks = calculate_average_marks(marks)highest_mark = find_highest_mark(marks)("Marks:", marks)print("Average mark:", average_marks)print("Highest mark:", highest_mark)print("Lowest mark:", lowest_mark)print("Number of students scoring above average:", students_above_average)```This will output:```Marks: [85, 90, 78, 92, 88]Average mark: 86.6Highest mark: 92Lowest mark: 78Number of students scoring above average: 3```