1
00:00:00,210 --> 00:00:03,900
All right. So hopefully everything we've learned in the last lesson made sense,

2
00:00:04,230 --> 00:00:08,670
and you're ready to put your knowledge to the test by completing the first

3
00:00:08,670 --> 00:00:09,750
coding challenge today.

4
00:00:10,410 --> 00:00:13,410
And what you're going to be building is a grading program.

5
00:00:13,650 --> 00:00:17,610
So if you take a look at the day 9.1 grading program

6
00:00:17,970 --> 00:00:21,270
Repl.it coding exercise, you'll see that to begin,

7
00:00:21,330 --> 00:00:26,330
I've already created a dictionary with a bunch of student names and their test

8
00:00:26,970 --> 00:00:28,740
scores. Now,

9
00:00:28,770 --> 00:00:32,430
without changing any of the code above here or below here,

10
00:00:32,850 --> 00:00:37,850
I want you to write a program that will be able to convert these scores into a

11
00:00:38,550 --> 00:00:43,170
grade. So the grading criteria is over here in the instructions.

12
00:00:43,590 --> 00:00:46,590
So if the student's scores above 91,

13
00:00:46,980 --> 00:00:51,750
then they'll get the grade outstanding. If they score above 81,

14
00:00:51,750 --> 00:00:54,510
they get exceeds expectations and then acceptable.

15
00:00:54,840 --> 00:00:58,980
And then finally everybody's scoring 70 or a lower gets the fail grade.

16
00:00:59,790 --> 00:01:00,623
Essentially,

17
00:01:00,720 --> 00:01:04,800
what you're going to be doing is creating an empty dictionary from scratch

18
00:01:05,100 --> 00:01:06,960
which is going to be called student_grades.

19
00:01:07,440 --> 00:01:12,440
And you're going to write some code so that each of the students are represented

20
00:01:12,870 --> 00:01:14,490
inside this new dictionary.

21
00:01:14,970 --> 00:01:19,260
And instead of having scores as the value's in that dictionary,

22
00:01:19,530 --> 00:01:23,940
you are going to have the grades that correspond to the scores that they got.

23
00:01:24,540 --> 00:01:28,320
Have a read through the instructions and the hints if you need some help,

24
00:01:28,710 --> 00:01:32,460
but once you're ready, go ahead and pause the video and give this a go.

25
00:01:32,660 --> 00:01:37,660
[inaudible]

26
00:01:39,050 --> 00:01:42,440
<v 0>All right. So to begin, let's first tackle this to-do 1.

27
00:01:42,950 --> 00:01:47,300
Let's create a new empty dictionary called student_grades.

28
00:01:48,560 --> 00:01:53,240
And the student_grades has to be spelled exactly the same as you see here,

29
00:01:53,510 --> 00:01:55,970
because otherwise this print statement will not work.

30
00:01:56,570 --> 00:01:58,730
The student_grades is gonna be an empty dictionary,

31
00:01:58,760 --> 00:02:01,610
which if you remember from the last lesson, we said

32
00:02:01,640 --> 00:02:05,480
it looks like this with two curly braces and nothing inside.

33
00:02:06,230 --> 00:02:08,780
Now let's move on to todo number 2.

34
00:02:09,020 --> 00:02:14,020
So we're going to write some code below so that we actually add the grades to

35
00:02:14,570 --> 00:02:16,850
this student grades dictionary.

36
00:02:17,330 --> 00:02:21,710
And we of course can get those grades by looking at each of the student's

37
00:02:21,740 --> 00:02:25,460
scores. How can we do this? Well,

38
00:02:25,460 --> 00:02:30,050
we're probably going to need a for loop because there's lots of items in this

39
00:02:30,050 --> 00:02:34,730
dictionary. Let's go ahead and loop through this student_scores dictionary,

40
00:02:35,270 --> 00:02:39,500
and I'm going to call each of the items the student,

41
00:02:39,740 --> 00:02:44,740
because remember when we have a for loop looping through a dictionary like we

42
00:02:45,320 --> 00:02:46,250
are doing here,

43
00:02:46,910 --> 00:02:51,860
each of the items that gets picked out is actually the key rather than the whole

44
00:02:51,860 --> 00:02:55,340
item. So again, we talked about this in the last lesson,

45
00:02:55,850 --> 00:03:00,670
but hopefully, this should really make it clear. But even if you didn't know,

46
00:03:00,910 --> 00:03:03,670
you could always of course just print it, right?

47
00:03:03,760 --> 00:03:07,090
So if we go ahead and use the for loop and print it,

48
00:03:07,090 --> 00:03:12,090
you can see we get all of the keys from this dictionary when we're looping

49
00:03:13,780 --> 00:03:17,080
through it. So for each of the students,

50
00:03:17,110 --> 00:03:19,210
we want to get hold of their score.

51
00:03:19,630 --> 00:03:23,200
We can calculate the score by getting hold of the value

52
00:03:23,440 --> 00:03:27,460
using this key from this dictionary. And to do that,

53
00:03:27,640 --> 00:03:30,520
if you remember, is tapping in to the dictionary,

54
00:03:31,000 --> 00:03:35,320
adding a set of square brackets and then giving it the key. So in this case,

55
00:03:35,320 --> 00:03:40,210
it's going to be each of the student names. And once we've got a hold of the

56
00:03:40,210 --> 00:03:43,570
score, well then we can use our if statement to check well

57
00:03:43,840 --> 00:03:46,480
if the score is greater than 90,

58
00:03:47,170 --> 00:03:48,940
so anything above 90,

59
00:03:49,270 --> 00:03:53,020
then that means they're going to end up with outstanding.

60
00:03:53,530 --> 00:03:58,530
Now, this is the part where we add a new entry to this student_grades dictionary.

61
00:03:59,230 --> 00:04:04,000
So let's tap into the dictionary, use a set of square brackets again

62
00:04:04,060 --> 00:04:06,640
to give it a key. And the key,

63
00:04:06,640 --> 00:04:10,360
of course, should still be the student name which comes from here,

64
00:04:10,900 --> 00:04:12,850
which is going to be the same as this.

65
00:04:13,360 --> 00:04:17,770
Then we can add a equal sign and followed by the value

66
00:04:18,220 --> 00:04:20,380
which is going to be outstanding.

67
00:04:21,670 --> 00:04:25,780
So now we can repeat this process for the rest of these grades.

68
00:04:26,130 --> 00:04:26,963
Yeah.

69
00:04:29,130 --> 00:04:34,020
Everybody who scored above 80 but not above 90, so remember that this

70
00:04:34,020 --> 00:04:38,640
if statement once triggered, will skip all of the rest of the elif statements.

71
00:04:41,700 --> 00:04:46,290
And then if they scored above 70, they would get acceptable. And finally,

72
00:04:46,290 --> 00:04:49,740
for everybody else, which means they scored lower than 70,

73
00:04:50,100 --> 00:04:52,710
then they're going to end up with a fail grade.

74
00:04:53,700 --> 00:04:58,590
Now it's really important that if you want the test to pass that each of these

75
00:04:58,590 --> 00:05:02,430
strings has to match what you see over here exactly.

76
00:05:03,120 --> 00:05:07,320
Now that we've done all of this hard work, manipulating our dictionary,

77
00:05:07,710 --> 00:05:12,210
it's time to actually go ahead and run our code and see what we get.

78
00:05:12,840 --> 00:05:15,060
So now our code has converted

79
00:05:15,090 --> 00:05:18,300
each of these scores to the corresponding grade.

80
00:05:18,750 --> 00:05:23,750
Harry gets exceeds expectations because his score is between 81 and 90, Ron gets

81
00:05:25,320 --> 00:05:29,340
acceptable because it's between 70 and 80, and so on and so forth.

82
00:05:30,300 --> 00:05:31,770
Now, did you manage to get it right,

83
00:05:32,220 --> 00:05:35,700
or did you have any problems working with dictionaries? Now,

84
00:05:35,760 --> 00:05:37,290
if you go beyond this lesson

85
00:05:37,320 --> 00:05:41,400
I'm going to assume that you are comfortable with editing dictionaries,

86
00:05:41,430 --> 00:05:43,500
adding to it, creating new ones.

87
00:05:43,980 --> 00:05:47,880
So if you are not yet fully there, then I recommend just going back to the last

88
00:05:47,880 --> 00:05:49,890
lesson, just reviewing it once more.

89
00:05:50,910 --> 00:05:53,280
Once you've done that, head over to the next lesson

90
00:05:53,490 --> 00:05:58,230
and we're going to talk more about nesting in dictionaries and lists. For all of that

91
00:05:58,470 --> 00:05:59,820
and more, I'll see you there.

