00:01
We are going to write a program in python with the following characteristics.
00:07
First, ask the user to enter the number of students in the range from 1 to 10.
00:14
Second, then the program asked the user to enter the number of tests in the range of 1 to 5.
00:22
Number 3, they then use a loop to collect the scores for those many tests for each student.
00:29
The outer loop will iterate once for each student.
00:32
Student while the inner loop will iterate several times once for each test.
00:39
Each iteration of the inner loop will ask the user to enter the score for a test of a student.
00:46
And finally, after all iterations, the berm should calculate and display the total scores and average score for each student.
00:55
So here we have a piece of code in python that solved this problem.
01:01
So let's follow it.
01:03
First we ask the user to enter the number of students in the range of 1 to 10 here.
01:08
We print that message in order for the user to know that he or she got to enter that number.
01:18
We read that as an input and remember that in python, any input is a string.
01:24
So we try to convert that input into a number.
01:30
Using the function int on the input data string.
01:34
So we use a try accept, try works well, that is the function in can convert the string into an integer number.
01:48
Then the program is going to continue, but if that's not the case, there is an exception and we print that the data is incorrect and try again, but we exit the program in that case.
01:59
That is the user got to run the program again to start all over.
02:05
Then if the data is correct for the number of students, we check that number of students to be in the range of 1 to 10.
02:16
That is, if the number of students is less than equal to 0 or greater than 10, we write a corresponding message on screen and exit the program.
02:28
After that, we ask the user to enter the number of tests in the range is an integer in the range of 1 to 5, and this is very similar to the case of the number of students.
02:39
That is we input the data into the variable input data is just the same variable in fact because we don't need to use another one.
02:47
We try to convert that into and into the number and save that in the norm test variable.
02:57
If that works well, the problem has that variable with the number of tests and if that's not the case, that is there is an exception.
03:05
The data is incorrect.
03:06
We put that message and exit the program.
03:10
Then we check if the number of tests in the variable numbed test is in the range of 1 to 5, that is if it's less than equal to 0 or greater than 5, we print out a message and stop the problem.
03:25
So here at this point, line 43, we know that two variables, num students and non -test contain the number of students and number of tests, respectively in order to start the loops.
03:43
And we need a structure to store data, the students and grades or scores, and that data will be a dictionary.
03:53
So we have a student will be the key values, that is we are going to label the students with the number in which we are introducing the data.
04:06
And then for each student, we have a list of numbers, which are the scores.
04:10
In each test for that student.
04:15
Okay, so we loop over the number of students here for i.
04:18
I will be the variable we use in the outer loop, and we loop that in the range numbed students.
04:26
Remember python is going to loop that variable when we put that in this way from zero to the number of students minus one.
04:37
And that is, in our case, is correct because we want to process all the students.
04:46
So for that student, we create what we call id students.
04:49
That will be the string that represents a student that is the word student and a number which corresponds to the order in which we are introducing the data.
05:01
And i use i plus one because i start at zero.
05:06
So for i equals zero, for example, which is the first student, we use the number zero plus one that is so for the first student, it will have the identifier as student want.
05:18
The second will be student two and so on.
05:22
And here you can see we have we are concatenating with this plus sign.
05:27
The number i plus one but we got to use the string function to convert that number to string in order that that concatenation works well.
05:39
Then we use a dictionary we created here.
05:43
Remember this is a way to create an empty dictionary and here we are creating the empty list for that student that is test score at the key value created in the previous line is equal to an empty list and that is to have the list created to add this course that we will read in the next loop so we print that that the score for that student with this id are going to be read in the inner loop...