0:01
Hey friends, welcome back to simplified
0:03
by singingum. Welcome to our Python
0:05
journey. So far we have learned how to
0:07
find the largest numbers and even we
0:09
worked with leap years in the previous
0:11
exercise as well and we have covered few
0:15
important Python basics till now. So now
0:18
we are working on exercises so that you
0:21
guys can get more use of the basics that
0:24
we have learned before. So in exercise
0:28
three, we are going to write a program
0:30
to check if a number is positive,
0:32
negative or zero. It sounds simple, but
0:35
trust me, this exercise will help you
0:37
build a strong foundation in using if
0:40
else conditions. And let's go step by
0:42
step. Always try to work on flowchart
0:45
before solving a problem because a
0:47
flowchart helps us to understand the
0:49
path the program should follow. So if
0:53
the number is greater than zero it's
0:55
positive and if the number is less than
0:57
zero then it's negative. It's as simple
0:59
as that. You will start the program you
1:02
will get the number you will check
1:04
whether it is greater than zero or not.
1:06
If it is greater than zero then this
1:08
will be true then it will print that the
1:11
number is positive. Else it will print
1:13
that the number is negative and then it
1:15
comes out of the loop.
1:19
Okay let's start then. So always get
1:27
number equal to input
1:36
and now you'll be getting a doubt called
1:38
whether I have to take integer or float
1:42
to observe these use cases here they
1:45
used integer and they also used float so
1:49
I think it's better to take float
2:03
check the conditions.
2:17
the number is positive.
2:27
the number is negative.
2:36
And what if the number is zero? What if
2:39
the number equal to zero? If you check
2:42
this condition, you also have to show
2:45
them that a number is zero. So it's very
2:48
simple. You just have to add l if
2:56
equal to zero then just print
3:11
So let's break this down slowly. So even
3:13
if you're coding for the first time,
3:15
you'll get it for sure. So first we ask
3:18
the user to enter a number. And I used
3:21
float. So we can check both integers and
3:25
even decimals. And then we used if else
3:30
structure. If the number is greater than
3:32
zero then you will print the number is
3:34
positive. If the number is zero then you
3:38
will just say the number is zero. Else
3:40
obviously the number will be negative so
3:42
the number is negative.
3:45
And that's it. Python makes it super
3:47
simple. And let's run the program and
3:58
Enter a number. Maybe seven.
4:01
The number is positive. Okay. Let's give
4:11
and enter a number - 3.14.
4:16
The number is negative. Okay.
4:22
Enter number zero. The number is zero.
4:27
Works perfectly in all cases. It's as
4:30
simple as that. If it is greater than
4:32
zero, then this condition will be
4:33
executed. If the number is zero, then
4:35
this condition. Else the number is
4:37
negative. And that's how you check
4:39
whether a number is positive, negative
4:41
or zero in Python. And the key takeaway
4:45
here is always break your problem into
4:48
small conditions. And flowcharts are
4:50
like your road map. They make coding
4:52
much easier. If you found this
4:54
explanation simple and clear, then don't
4:57
forget to do two small favors for me.
5:00
One is to hit that subscribe button so
5:02
you don't miss the next exercise. And
5:05
also give this video a like because your
5:08
support motivates me to bring you more
5:10
beginner friendly coding lessons. And
5:12
also remember, every line of code you
5:15
write takes you one step closer to
5:17
becoming a confident programmer. Keep
5:20
practicing. Stay curious. And I'll see