0

Using python program to find the average marks of all subject for all the following students:

Student ID  | Quiz   | Research Project | Assignment     | Final Exam                   
1           | 40/50  | 50/100           | 15/20          | 50/100
2           | 50/50  | 30/100           | 10/20          | 10/100
3           | 22/50  | 43/100           | 8/20           | 30/100
4           | 40/50  | 36/100           | 19/20          | 43/100
5           | 20/50  | 80/100           | 11/20          | 51/100

Rules to follow:

  1. Use 2-Dimensional Array to store the above data (must be float) and perform calculation. Make sure the average is printed in 2 decimal point. (exclude student ID and header in array)
  2. Store your 2D array with variable markss
  3. Make sure your algorithm able to support different size of array.

The sample output should look exactly like that:

student 1 have 63.75 average.
student 2 have 47.50 average.
student 3 have 39.25 average.
student 4 have 63.50 average.
student 5 have 56.50 average.

I have tried to code it, below is my code:

markss = [[0.8, 0.5, 0.75, 0.5], [1, 0.3, 0.5, 0.1], [0.44, 0.43, 0.4, 
0.3], [0.8, 0.8, 0.95, 0.43], [0.4, 0.8, 0.55, 0.51]]


average = [(sum(avg)/float(len(avg)))*100 for avg in markss]

print(f"student 1 have {average[0]:.2f} average.")
print(f"student 2 have {average[1]:.2f} average.")
print(f"student 3 have {average[2]:.2f} average.")
print(f"student 4 have {average[3]:.2f} average.")
print(f"student 5 have {average[4]:.2f} average.")
4
  • 3
    Have you written any code to do that? We don't solve peoples' homework here, but we do help with concrete issues with your code Commented Mar 8, 2021 at 13:03
  • Hi ForceBru, I have written my code but it's wrong and I don't know how to fix it. @ForceBru Commented Mar 8, 2021 at 13:16
  • Wrong in what way? Commented Mar 8, 2021 at 13:24
  • Hi Heiki, my code is not able to fulfill criteria 3. @Heiki Commented Mar 8, 2021 at 14:51

1 Answer 1

1
my2dlist = []           # declare normal list

my2dlist.append([x for x in range(2)])   # adding lists
my2dlist.append([x for x in range(9)])   

print(my2dlist)

print(my2dlist[0][1])   # accessing entry
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.