1
00:00:00,000 --> 00:00:02,640
Now the goal of this exercise is

2
00:00:02,640 --> 00:00:06,000
to write a program using what you've learned about if

3
00:00:06,000 --> 00:00:09,330
and else conditional statements to figure out

4
00:00:09,330 --> 00:00:14,330
whether if an input number is odd or even.

5
00:00:14,430 --> 00:00:17,670
So what differentiates odd and even numbers?

6
00:00:17,670 --> 00:00:21,720
Well, even numbers, by definition, can be divided

7
00:00:21,720 --> 00:00:24,870
by two with no remainder.

8
00:00:24,870 --> 00:00:29,340
That means that the final result has no decimal places.

9
00:00:29,340 --> 00:00:33,360
It's a whole number and the division is clean.

10
00:00:33,360 --> 00:00:35,610
Whereas if you took an odd number,

11
00:00:35,610 --> 00:00:38,460
like three, and divided it by two,

12
00:00:38,460 --> 00:00:41,820
the result is 1.5, and it does have a decimal place.

13
00:00:41,820 --> 00:00:44,040
It's not a whole number.

14
00:00:44,040 --> 00:00:48,090
In Python and in many other programming languages,

15
00:00:48,090 --> 00:00:49,830
there's a way to check

16
00:00:49,830 --> 00:00:53,220
if a division occurs with no remainder,

17
00:00:53,220 --> 00:00:56,310
and that is through something called the modulo.

18
00:00:56,310 --> 00:01:00,630
Now, you can use the modulo by writing a percentage sign %

19
00:01:00,630 --> 00:01:04,379
and that will give you the remainder after a division.

20
00:01:04,379 --> 00:01:09,380
For example, if you divide six by two, that equals three

21
00:01:09,750 --> 00:01:11,580
with no remainder.

22
00:01:11,580 --> 00:01:16,383
So if 6 % 2, the result would be 0.

23
00:01:17,670 --> 00:01:22,620
But if you try to divide five by two, then two can go

24
00:01:22,620 --> 00:01:27,620
into five two times, but there is one remainder.

25
00:01:28,260 --> 00:01:32,010
So five modulo two is equal to one (5 % 2  = 1).

26
00:01:32,010 --> 00:01:34,410
You can take a look in the description pane to

27
00:01:34,410 --> 00:01:39,410
see this written out and understand how the modulo works

28
00:01:40,380 --> 00:01:43,470
and you can get more details on the modulo by Googling

29
00:01:43,470 --> 00:01:44,313
for it as well.

30
00:01:45,180 --> 00:01:50,180
In our case, we want our code to be able to check the input

31
00:01:50,880 --> 00:01:54,300
number and it's ready coming in, and we're converting it

32
00:01:54,300 --> 00:01:55,980
into a whole number.

33
00:01:55,980 --> 00:01:59,280
And we're going to check to see if it's odd, or even.

34
00:01:59,280 --> 00:02:02,760
If it's odd, we're going to print into the output,

35
00:02:02,760 --> 00:02:05,250
"This is an odd number."

36
00:02:05,250 --> 00:02:06,750
And if it's even, we're going to print,

37
00:02:06,750 --> 00:02:09,539
"This is an even number."

38
00:02:09,539 --> 00:02:12,690
That is the task at hand, and now it's for you

39
00:02:12,690 --> 00:02:15,900
to start struggling and trying to figure out

40
00:02:15,900 --> 00:02:18,663
how to solve this code exercise.

41
00:02:22,860 --> 00:02:24,900
The first thing we're going to check using an

42
00:02:24,900 --> 00:02:28,410
if statement is if the value that's stored

43
00:02:28,410 --> 00:02:33,410
in our variable number is divisible by two

44
00:02:33,450 --> 00:02:37,590
and has no remainder, and we're going to do this using

45
00:02:37,590 --> 00:02:41,670
the modulo, so number % 2, and then we

46
00:02:41,670 --> 00:02:46,670
use the double equal (==) sign to check to see if it equals 0.

47
00:02:47,040 --> 00:02:52,020
And this is equivalent to saying if number divided

48
00:02:52,020 --> 00:02:56,190
by 2 has no decimal places, well then in that case

49
00:02:56,190 --> 00:02:58,470
it must be an even number.

50
00:02:58,470 --> 00:03:01,500
So that's why on the next line, Line 6,

51
00:03:01,500 --> 00:03:04,560
we have an indented print statement.

52
00:03:04,560 --> 00:03:08,460
This print statement is going to be carried

53
00:03:08,460 --> 00:03:13,460
out if the Line 5 condition is true.

54
00:03:15,270 --> 00:03:18,960
If the input was indeed an even number,

55
00:03:18,960 --> 00:03:23,760
say it was Number 4, 4/ 2,

56
00:03:23,760 --> 00:03:27,300
2 goes into 4 twice, and there is no remainder.

57
00:03:27,300 --> 00:03:28,133
So therefore

58
00:03:28,133 --> 00:03:31,830
the modulo operator gives us a result of 0.

59
00:03:31,830 --> 00:03:34,230
So if that condition is true, it's going to fall

60
00:03:34,230 --> 00:03:37,680
into the indented print statement and printout,

61
00:03:37,680 --> 00:03:39,873
"This is an even number."

62
00:03:40,800 --> 00:03:44,850
Alternatively, or in this case, in the else condition,

63
00:03:44,850 --> 00:03:49,850
so if Line 5  condition was false, it did not work

64
00:03:51,180 --> 00:03:54,180
and there was a remainder, then we're going to print out,

65
00:03:54,180 --> 00:03:56,583
"This is an odd number."

66
00:03:57,660 --> 00:04:00,930
This is a way that we can manipulate numbers

67
00:04:00,930 --> 00:04:03,330
and check them and use what we learned

68
00:04:03,330 --> 00:04:06,750
about conditionals to check if a condition is true

69
00:04:06,750 --> 00:04:10,890
and behave in a certain way, or if that condition was false,

70
00:04:10,890 --> 00:04:14,220
then our program should behave in a different way.

71
00:04:14,220 --> 00:04:16,110
If you need to make any changes to your code

72
00:04:16,110 --> 00:04:17,010
feel free to go back

73
00:04:17,010 --> 00:04:20,130
to the previous slide and make those changes.

74
00:04:20,130 --> 00:04:21,660
Don't feel like you've failed

75
00:04:21,660 --> 00:04:22,860
or you're cheating or whatever.

76
00:04:22,860 --> 00:04:25,620
This is all a part of the learning process.

77
00:04:25,620 --> 00:04:26,610
It's okay to look

78
00:04:26,610 --> 00:04:29,550
at the solution and learn from the solution too.

79
00:04:29,550 --> 00:04:32,300
You don't have to figure everything out the first time.

