1
00:00:00,600 --> 00:00:03,060
In this exercise, you are going to create

2
00:00:03,060 --> 00:00:07,980
a program that grades a student's test scores.

3
00:00:07,980 --> 00:00:12,180
You'll see on lines 1 to 7, that we've got a dictionary,

4
00:00:12,180 --> 00:00:14,310
and it's called student_scores.

5
00:00:14,310 --> 00:00:15,390
Inside the dictionary,

6
00:00:15,390 --> 00:00:18,120
the keys are the names of our students,

7
00:00:18,120 --> 00:00:21,450
and the values are their test scores.

8
00:00:21,450 --> 00:00:24,810
What you are going to do is using a for loop to loop

9
00:00:24,810 --> 00:00:27,600
through the dictionary, you're going to write a program

10
00:00:27,600 --> 00:00:31,320
that can interpret each student's scores

11
00:00:31,320 --> 00:00:36,320
and create a new dictionary called student_grades

12
00:00:36,390 --> 00:00:40,650
and in this dictionary, you have the student names matching

13
00:00:40,650 --> 00:00:43,110
with their corresponding grades.

14
00:00:43,110 --> 00:00:46,050
If you take a look inside the Description pane,

15
00:00:46,050 --> 00:00:50,580
you will see the scores and their corresponding grades.

16
00:00:50,580 --> 00:00:54,330
So for example, a score of 91 to 100 is interpreted

17
00:00:54,330 --> 00:00:58,680
as Outstanding, 81 to 90 is Exceeds Expectations,

18
00:00:58,680 --> 00:01:00,420
and so on and so forth.

19
00:01:00,420 --> 00:01:04,470
Take a look at the Expected Output and see if you can

20
00:01:04,470 --> 00:01:08,310
figure out how to use a loop on a dictionary

21
00:01:08,310 --> 00:01:12,720
in order to make your program work as expected.

22
00:01:12,720 --> 00:01:13,570
Give it a go now.

23
00:01:21,450 --> 00:01:24,900
The first thing I'm going to do is to create a dictionary

24
00:01:24,900 --> 00:01:26,610
called student_grades

25
00:01:26,610 --> 00:01:30,060
and simply have it as an empty dictionary { }.

26
00:01:30,060 --> 00:01:33,243
This is what we're going to fill up using our program.

27
00:01:34,290 --> 00:01:37,860
Next, I'm going to create a for loop that loops through

28
00:01:37,860 --> 00:01:42,240
the dictionary of student_scores so that I can get hold

29
00:01:42,240 --> 00:01:45,333
of each of the keys in that dictionary one by one.

30
00:01:46,320 --> 00:01:49,110
In order to access that student_score,

31
00:01:49,110 --> 00:01:52,590
I have to use the key on the student_scores dictionary.

32
00:01:52,590 --> 00:01:57,270
So exact line of code looks like line 14 where the score,

33
00:01:57,270 --> 00:01:59,640
the variable that I'm interested in storing

34
00:01:59,640 --> 00:02:01,410
is equal to student_scores,

35
00:02:01,410 --> 00:02:05,190
passing in each of the student names as the key,

36
00:02:05,190 --> 00:02:09,330
and now what the score will equal is the first time

37
00:02:09,330 --> 00:02:11,880
my loop runs, it'll equal to 81.

38
00:02:11,880 --> 00:02:13,290
Next time it'll be 78.

39
00:02:13,290 --> 00:02:16,023
Next time it'll be 99, and so on and so forth.

40
00:02:17,430 --> 00:02:19,950
Now comes the easier part where I have my if,

41
00:02:19,950 --> 00:02:23,730
elif, else statements, and I simply use the criteria

42
00:02:23,730 --> 00:02:28,320
that's in the Description pane to determine how each score

43
00:02:28,320 --> 00:02:29,820
is going to be interpreted.

44
00:02:29,820 --> 00:02:32,340
So if the score is greater than 90,

45
00:02:32,340 --> 00:02:34,920
then I can take the student_grades,

46
00:02:34,920 --> 00:02:37,680
which is our empty dictionary, empty for now,

47
00:02:37,680 --> 00:02:41,340
and then use the square brackets [ ] to assign the student,

48
00:02:41,340 --> 00:02:43,980
which is what we're looping on at the moment.

49
00:02:43,980 --> 00:02:46,500
That's going to be the name of the student,

50
00:02:46,500 --> 00:02:50,790
and set it to equal a value, which is going to be the grade.

51
00:02:50,790 --> 00:02:53,940
And I can do that if the score is greater than 80

52
00:02:53,940 --> 00:02:56,280
and if the score is greater than 70.

53
00:02:56,280 --> 00:02:59,940
And remember, because the way that if, elif, else statements work, 

54
00:02:59,940 --> 00:03:01,980
is they work like a waterfall.

55
00:03:01,980 --> 00:03:03,570
So if the first one is false,

56
00:03:03,570 --> 00:03:05,070
then it goes to the second one.

57
00:03:05,070 --> 00:03:08,220
So even though we're only checking on line 17,

58
00:03:08,220 --> 00:03:10,620
that elif score is greater than 80

59
00:03:10,620 --> 00:03:14,070
because the first one already went into the elif

60
00:03:14,070 --> 00:03:18,210
that means the first condition on line 15 is already False.

61
00:03:18,210 --> 00:03:22,500
So that basically means that the score that we are assigning

62
00:03:22,500 --> 00:03:27,500
exceeds expectations on 18 is between 80 and 90.

63
00:03:28,440 --> 00:03:30,390
Now, the way that dictionaries work with the key

64
00:03:30,390 --> 00:03:32,550
and the value and how you access a value

65
00:03:32,550 --> 00:03:35,490
through the key can be a little bit mysterious

66
00:03:35,490 --> 00:03:37,140
but if you use print statements

67
00:03:37,140 --> 00:03:41,880
and evaluate what your beliefs and reality and compare them

68
00:03:41,880 --> 00:03:43,110
then you should be able to get

69
00:03:43,110 --> 00:03:45,810
to a point where you can solve the puzzle and figure out

70
00:03:45,810 --> 00:03:48,540
how to make the program do what you want it to.

71
00:03:48,540 --> 00:03:50,400
So if you needed to make any fixes now,

72
00:03:50,400 --> 00:03:51,450
go ahead and do that.

