Let me explain this a lot easier:
pets = ['cat', 'dog'] ages = [5, 7] for pet, age in pets, ages: print(pet, age)
What is printed here:
cat dog 5 7
The crucial question is what is really going on here. It turns out that pets, ages is actually a tuple. Expressions separated by commas are called expression-lists .
This is a tuple containing 2 lists, it looks like this: (['cat', 'dog'], [5, 7]) . Therefore, when you iterate over it, the following interesting thing arises: Iterative unpacking!
Basically what is happening now:
pet, age = ['cat', 'dog']
And at the next iteration:
pet, age = [5, 7]
How did you get an initially amazing result.
The reason for the second problem that you encountered is that you supply only one name, at the first iteration it happened (let the pets example still be used):
pet, age = ['python']
ValueError: need more than 1 value to unpack
To fix both problems, you can use the built-in zip function .
for studentname, studread in zip(student_name, student_result_reading): print('Student Name: {} | Test Name: Reading Test | Percentage Score: {}'.format(studentname, studread))
You can also use the so-called f-strings to format the output, they are available with Python 3.6
for studentname, studread in zip(student_name, student_result_reading): print(f'Student Name: {studentname} | Test Name: Reading Test | Percentage Score: {studread}')