Questions about Python List

Asked 2 years ago, Updated 2 years ago, 96 views

To solve this problem #4

for i in range(len(table[0])) :
  print(table[0][i])
  sum=0
  for j in range(1,len(table)) :
    for k in range(1,len(table[j])) :
      sum=sum+table[j][k]
  print("total score",sum",means",sum/(len(table)-1)))

I did it like this.

This value came out, so I tried to repeat the outer for door first, but it didn't work, so I wanted to use only one for door.

student=["A","B","C","D","E"]
score1=["Korean",89,90,75,96,75]
score2=["English",92,65,82,65,98]
score3=["Math",78,88,68,92,45]
score4=["Science",66,78,88,95,85]

table=[student,score1,score2,score3,score4]

for i in range(len(table[0])) :
  print (table[0][i],"Student")
  sum=0
  for j in range(1,5) :
    sum=table[1][j]+table[2][j]+table[3][j]+table[4][j]
  print("total score",sum",means",sum/(len(table)-1)))

I did it like this, but now

I don't know how to solve it now because the total score was wrong and the scores for each student were the same. I've been trying to solve this problem for eight hours, but I don't know how to turn the for door upside down, and I don't know why I only get the same price. Masters, please help me.

python for list

2022-09-20 22:11

1 Answers

student=["A","B","C","D","E"]
score1=["Korean",89,90,75,96,75]
score2=["English",92,65,82,65,98]
score3=["Math",78,88,68,92,45]
score4=["Science",66,78,88,95,85]

table=[student,score1,score2,score3,score4]

for i in range(len(table[0])) :
    print (table[0][i],"Student")
    sum=0
    sum=table[1][i+1]+table[2][i+1]+table[3][i+1]+table[4][i+1]
    print("total score",sum",means",sum/(len(table)-1)))

You can do it like this.

I think that's how I found the problem. Please refer to it.


2022-09-20 22:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.