Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,300 --> 00:00:03,270
All right, so now let's solve this exercise together.
2
00:00:03,600 --> 00:00:07,410
So first of all, what we want to do is to create a great variable.
3
00:00:07,410 --> 00:00:08,910
So eins, great.
4
00:00:09,180 --> 00:00:15,210
So just to remind you, what we want to do is that we simply want to write a program that will read
5
00:00:15,330 --> 00:00:21,600
different grades, one after the other, until the user inserts a valid grade, which is which should
6
00:00:21,600 --> 00:00:29,730
be between, you know, between less like greater than zero greater or equal to zero.
7
00:00:30,150 --> 00:00:33,600
And of course, last van or equals to a hundred.
8
00:00:33,870 --> 00:00:41,610
So until the user will not insert these grade, we will ask him to to try again.
9
00:00:41,910 --> 00:00:42,300
All right.
10
00:00:42,330 --> 00:00:45,630
So here we actually can use this approach.
11
00:00:45,660 --> 00:00:46,650
So print half.
12
00:00:48,120 --> 00:00:48,780
Answer.
13
00:00:49,250 --> 00:00:52,310
Answer a grade between zero to one hundred.
14
00:00:52,320 --> 00:00:55,270
Between zero to a hundred.
15
00:00:56,250 --> 00:00:58,830
And we will ask the user to insert a grade.
16
00:00:58,980 --> 00:01:03,070
Now we are going to read it using this kind of functional percentage, the.
17
00:01:03,480 --> 00:01:06,360
And place it inside of the grade variable.
18
00:01:06,660 --> 00:01:12,660
And now we are going to use, of course, the while loop to check if the grade.
19
00:01:12,900 --> 00:01:13,710
That was the insert.
20
00:01:13,720 --> 00:01:14,490
That is correct.
21
00:01:14,730 --> 00:01:17,760
If not, we are going to ask for a new grade.
22
00:01:17,910 --> 00:01:21,180
Over and over again until it's going to be correct.
23
00:01:21,270 --> 00:01:23,790
So use the while and specify the while.
24
00:01:23,790 --> 00:01:26,970
Loop the condition and the condition in such a case will be.
25
00:01:27,230 --> 00:01:27,740
Will be.
26
00:01:27,900 --> 00:01:39,660
As long as grade is less of them is less than zero or or or a logical or if as long as grade is greater
27
00:01:39,840 --> 00:01:41,010
than a hundred.
28
00:01:41,040 --> 00:01:47,370
So as long as one of them of these condition, either one of them is now happens to be true, we are
29
00:01:47,370 --> 00:01:49,180
going to execute this loop.
30
00:01:49,280 --> 00:01:56,970
And in this note, we are going to use the same, the same lines as we've used before the while loop.
31
00:01:57,240 --> 00:02:00,750
So just coffee and face that you use it like this.
32
00:02:00,900 --> 00:02:01,440
All right.
33
00:02:01,440 --> 00:02:05,100
So print f anterograde between zero to a hundred.
34
00:02:05,160 --> 00:02:09,030
We these grade until the user wheelings are the correct grade.
35
00:02:09,330 --> 00:02:16,230
And once we are done out of the slope, we are going to print a corresponding message and something
36
00:02:16,230 --> 00:02:16,800
like that.
37
00:02:16,890 --> 00:02:17,490
Thanks.
38
00:02:17,970 --> 00:02:22,160
You have inserted L.A., Jude.
39
00:02:23,130 --> 00:02:27,300
At grade of the percentage there and backslash.
40
00:02:27,300 --> 00:02:33,330
And at the end we are just going to specify the grade that the user inserted between zero to a hundred.
41
00:02:33,420 --> 00:02:37,560
So basically this program will work and let's try to build and run it.
42
00:02:37,650 --> 00:02:38,940
Let's write a bill and run it.
43
00:02:39,360 --> 00:02:42,630
So let's say we are going to give it like minus five.
44
00:02:43,080 --> 00:02:47,640
So it will still ask us to insert another grade, let's say a thousand.
45
00:02:48,090 --> 00:02:56,170
No, they here you can see in the prompt that it asks says to anterograde between zero to hundred.
46
00:02:56,310 --> 00:03:00,570
So if you want to make each correct, you should insert the grade between this range.
47
00:03:00,600 --> 00:03:02,010
So in this range.
48
00:03:02,040 --> 00:03:03,620
So let's try 90.
49
00:03:03,960 --> 00:03:08,070
And we are getting a message, thinks you of insert that ltg the grade of 90.
50
00:03:08,610 --> 00:03:09,330
All right.
51
00:03:09,450 --> 00:03:10,710
So that works.
52
00:03:10,740 --> 00:03:17,520
But the only thing that has not been done in these exercises, the image of do while loops.
53
00:03:17,580 --> 00:03:20,160
And why would we like to to use here?
54
00:03:20,430 --> 00:03:21,390
Do while loops.
55
00:03:21,660 --> 00:03:24,000
Because we have a code duplication.
56
00:03:24,090 --> 00:03:29,460
You can see basically that these two lines are repeated here in this loop body.
57
00:03:29,550 --> 00:03:35,520
So in these type of questions, we are going in these type of cases we are going to use it to do while
58
00:03:35,790 --> 00:03:38,670
as we've just explained in the previous video.
59
00:03:39,540 --> 00:03:46,260
So we are just going to copy these while and the condition, put it inside after the curly brackets.
60
00:03:46,320 --> 00:03:48,690
That how you use the do while loops.
61
00:03:48,720 --> 00:03:52,590
And here we are going to specify that do what we want to do.
62
00:03:52,610 --> 00:03:59,670
We want to run these loop body as long as these condition happens to be true.
63
00:03:59,760 --> 00:04:02,370
So now, of course, we can remove these two lines.
64
00:04:02,610 --> 00:04:09,120
We've eliminated the code duplication and we know that for the first time we are going to enter the
65
00:04:09,120 --> 00:04:11,580
first iteration of this little body.
66
00:04:11,580 --> 00:04:16,500
We are going to execute these two lines regardless of the result of this condition.
67
00:04:16,860 --> 00:04:22,200
And after wars, we are going to insert these are just like we've done previously.
68
00:04:22,200 --> 00:04:24,840
So just let's build in running to make sure.
69
00:04:25,260 --> 00:04:26,250
Minus five.
70
00:04:26,820 --> 00:04:30,890
It asks us once again, one hundred and seven again.
71
00:04:30,990 --> 00:04:35,760
And if you use 50, then thinks you've answers the villager, the grade of 50.
72
00:04:36,240 --> 00:04:37,230
And there you go, guys.
73
00:04:37,260 --> 00:04:42,930
Basically these program works we used here do while loops instead of wire loops.
74
00:04:42,960 --> 00:04:46,950
We explained why would prefer one thing over the other.
75
00:04:47,070 --> 00:04:50,070
And I think we are done with this video.
6816
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.