다양한 모듈에서 학생들의 점수를 나타내는 테이블을 만들어야합니다. 다음과 같은 표현을 할 생각이었습니다.
Students, a list of strings that are student names. For each i such that
0 <=i <= len(Students) - 1, we refer to Students[i] as the i-th student.
Modules, a list of strings that are modules names. For each i such that
0 <=i <=len(Modules) - 1, we refer to Modules[i] as the i-th module.
Marks a table whose rows correspond to the students and columns correspond to the modules. Marks[i][j] is an integer number defined as follows.
{ If Marks[i][j] = -1 this means that the i-th student is not registered
for the j-th module.
{ If Marks[i][j] =>0 then this is the mark of the i-th student for the
j-th module. We can assume that the marks are in range 0-100,
there is no need to check the validity of the data.
예를 들면 다음과 같습니다.
students=['Artur', 'Igor', 'David', 'Andy']
modules=['DM', 'ISD', 'INS', 'IS']
marks=marks[i][j]=int
for i in range(0, len(students)-1) #i ranges over all row numbers
for i in range(0, len(students)-1) #j ranges over all indices
print(a[i][j])
나중에 행, 열, 마크의 평균을 계산하고 학생 보고서를 인쇄 할 수 있도록 테이블을 올바르게 작성하는 방법이 약간 혼란 스럽습니다. 알고리즘을 수정하여 일반 테이블을 작성하는 방법이 있습니까?
"표"가 작업에 가장 적합한 도구는 아닐 수 있지만 시작하려면 마크 목록을 만들고 필요한 곳에 추가하여 각 학생에 대한 새 목록을 시작해야합니다. 지금은 모든 것을 -1로 초기화합시다.
students=['Artur', 'Igor', 'David', 'Andy', 'Fran']
modules=['DM', 'ISD', 'INS', 'IS']
marks = []
for i in range(len(students)):
marks.append([])
for j in range(len(modules)):
marks[i].append(-1)
>>> marks
[[-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1]]
이제 목록 목록이 있습니다.
몇 가지 주목
-1
marks=marks[i][j]=int
아무 의미가 없습니다. 방금 목록을 작성하고 추가했습니다.이제 모듈의 점수를 변경하고 평균을 쉽게 찾을 수 있습니다.
>>> marks[0][1] = 50
>>> marks
[[-1, 50, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1, -1, -1], [-1, -1
, -1, -1]]
>>> for scores in marks:
... print sum(scores)/len(scores)
...
11
-1
-1
-1
-1
이제 사전과 같은 대안이 있는데,이를 통해 학생의 이름을 찾을 수 있습니다. 또는 심지어 defaultdict.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다