0

This is my code:

units_list = [['CITS1001', '95'], ['CITS1401', '100'], ['CITS1402', '97'], ['CITS2002', '99'], ['CITS2211', '94'], ['CITS2401', '95'], ['CITS3001', '93'], ['CITS3002', '93'], ['CITS3003', '91'], ['CITS3200', '87'], ['CITS3401', '98'], ['CITS3402', '93'], ['CITS3403', '88']]
students_list = [['Needie Seagoon', '57', '', '83', '55', '78', '', '91', '73', '65', '56', '', '', ''], ['Eccles', '', '98', '91', '80', '', '66', '', '', '', '77', '78', '48', '77'], ['Bluebottle', '61', '', '88', '80', '60', '', '45', '52', '91', '85', '', '', ''], ['Henry Crun', '92', '', '58', '50', '57', '', '67', '45', '77', '72', '', '', ''], ['Minnie Bannister', '51', '', '97', '52', '53', '', '68', '58', '70', '69', '', '', ''], ['Hercules Grytpype-Thynne', '', '78', '62', '75', '', '67', '', '', '', '48', '56', '89', '67'], ['Count Jim Moriarty', '51', '', '68', '51', '66', '', '55', '72', '50', '74', '', '', ''], ['Major Dennis Bloodnok', '', '54', '47', '59', '', '48', '', '', '', '66', '58', '53', '83']]

normalised = [[students_list[0]] +
[None if students_list is ''
else
## convert number string to float to count
float(studentScores) / float(units_list[index][1])
for index, studentScores in enumerate(students[1:])
] for students in students_list]

print(normalised)

and there is an error in this line:

for index, studentScores in enumerate(students[1:])

What should I change and what caused this problem?

1
  • The error in on the previous line. Commented Sep 14, 2018 at 15:49

2 Answers 2

1

Your expression

None if students_list is '' else float(studentScores)/float(units_list[index][1])

should probably be

None if studentScores is '' else float(studentScores)/float(units_list[index][1])
Sign up to request clarification or add additional context in comments.

Comments

0

The correct expression:

normalised=[[students[0]]+
[None if studentScores is ''
else
## convert number string to float to count
float(studentScores)/float(units_list[index][1])
for index, studentScores in enumerate(students[1:])
]for students in students_list]
print(normalised)

I found that the first line is also incorrect

and now, we can get a correct output:

[['Needie Seagoon', 0.6, None, 0.8556701030927835, 0.5555555555555556, 0.8297872340425532, None, 0.978494623655914, 0.7849462365591398, 0.7142857142857143, 0.6436781609195402, None, None, None], ['Eccles', None, 0.98, 0.9381443298969072, 0.8080808080808081, None, 0.6947368421052632, None, None, None, 0.8850574712643678, 0.7959183673469388, 0.5161290322580645, 0.875], ['Bluebottle', 0.6421052631578947, None, 0.9072164948453608, 0.8080808080808081, 0.6382978723404256, None, 0.4838709677419355, 0.5591397849462365, 1.0, 0.9770114942528736, None, None, None], ['Henry Crun', 0.968421052631579, None, 0.5979381443298969, 0.5050505050505051, 0.6063829787234043, None, 0.7204301075268817, 0.4838709677419355, 0.8461538461538461, 0.8275862068965517, None, None, None], ['Minnie Bannister', 0.5368421052631579, None, 1.0, 0.5252525252525253, 0.5638297872340425, None, 0.7311827956989247, 0.6236559139784946, 0.7692307692307693, 0.7931034482758621, None, None, None], ['Hercules Grytpype-Thynne', None, 0.78, 0.6391752577319587, 0.7575757575757576, None, 0.7052631578947368, None, None, None, 0.5517241379310345, 0.5714285714285714, 0.956989247311828, 0.7613636363636364], ['Count Jim Moriarty', 0.5368421052631579, None, 0.7010309278350515, 0.5151515151515151, 0.7021276595744681, None, 0.5913978494623656, 0.7741935483870968, 0.5494505494505495, 0.8505747126436781, None, None, None], ['Major Dennis Bloodnok', None, 0.54, 0.4845360824742268, 0.5959595959595959, None, 0.5052631578947369, None, None, None, 0.7586206896551724, 0.5918367346938775, 0.5698924731182796, 0.9431818181818182]]

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.