Premium Only Content

Conditionals |Section 3|Celestial Warrior
1
00:00:00,620 --> 00:00:05,720
Hey, hello again. In this lecture you're going to learn
about conditionals. What is a conditional?
3
00:00:07,980 --> 00:00:14,190
Well a conditional is a block of code which
performs different actions depending on
5
00:00:14,190 --> 00:00:19,980
whether a given conditional evaluates to
true or false so let's go ahead and
7
00:00:19,980 --> 00:00:29,340
create a conditional in Python. I'll create the
file conditionals dot py and let me
9
00:00:29,340 --> 00:00:35,280
create a conditional block, and first of
all let me create a variable. Let's say a
11
00:00:35,280 --> 00:00:40,920
equals five and here I'll create a
conditional block. This block, what this
13
00:00:40,920 --> 00:00:48,780
will do is it will perform an action if
a is less than five and another action
15
00:00:48,780 --> 00:00:54,930
if a is equal or greater than five
so let me create that. If this, our
17
00:00:54,930 --> 00:01:04,049
conditional starts if a and let's say
less than five print, let's say less than 5.
19
00:01:04,049 --> 00:01:15,030
Press ENTER and if you want to perform
more actions with this conditional, with
21
00:01:15,030 --> 00:01:19,979
this condition so when this condition is
true this will be executed but if you
23
00:01:19,979 --> 00:01:25,049
want to perform more actions you can add
one there, if not then you can go to the
25
00:01:25,049 --> 00:01:32,159
next check.
So that would be else, so you have a
27
00:01:32,159 --> 00:01:45,060
column here, a column there, so else print
equal or greater than 5. Now let me
29
00:01:45,060 --> 00:01:53,520
execute it. And we get equal or greater
than 5. So why did you get that? Well
31
00:01:53,520 --> 00:01:59,729
because you know if a is less than 5
which is not, so this evaluates to false,
33
00:01:59,729 --> 00:02:05,340
that means with this this will not be
executed so Python will skip this line
35
00:02:05,340 --> 00:02:12,870
and it will go to the next one. This next
line says else, so else means if this
37
00:02:12,870 --> 00:02:18,450
is not true,
this will be executed, so equal or
39
00:02:18,450 --> 00:02:25,769
greater than five, so in this case if a
is not less than five then there's no
41
00:02:25,769 --> 00:02:32,549
other option but a is either equal or
greater than five, so that's an if and else
43
00:02:32,549 --> 00:02:36,959
conditional block. However if you want to
add more conditions there
45
00:02:36,959 --> 00:02:45,569
you want to use elif, so let's do that
the first two lines stay the same. If a
47
00:02:45,569 --> 00:02:57,840
is less than five print less than five
elif a is equal to five print equal to
49
00:02:57,840 --> 00:03:19,019
five else print greater than five. Save
and execute and you get equal to five.
51
00:03:19,019 --> 00:03:21,769
If a was six,
you'd get greater than five and if a was
53
00:03:25,500 --> 00:03:34,500
three you'd get less than five.
That's a conditional block in Python and
55
00:03:34,500 --> 00:03:39,480
yeah, try to get familiar with the syntax
and in the next lecture I'm going to
57
00:03:39,480 --> 00:03:47,569
incorporate a conditional with this
block of code, so see you there.
-
LIVE
iCheapshot
2 hours agoBack From Vacation! | Checking Out Skate Maybe Some Boarderlands 4
173 watching -
LIVE
Jorba4
1 hour ago🔴Live-Jorba4- Borderlands w/ The TRIBE
68 watching -
54:43
Glenn Greenwald
5 hours agoGlenn Reacts to Netanyahu's UN Speech; PLUS: Q&A on Trump's Russia/Ukraine Policy, the Tom Homan Investigation, and More | SYSTEM UPDATE #522
54.2K37 -
43:54
Donald Trump Jr.
4 hours agoJames and the Giant Breach, Plus Explosive J6 Revelations | TRIGGERED Ep.277
144K169 -
LIVE
MadHouse_
4 hours agoFRIEND FRIDAY! - Garys Mod ? im pretty sure im gonna lose at this game
101 watching -
2:26:51
blackfox87
3 hours agoBorderlands Grind Continues | PREMIUM CREATOR | #DisabledVeteran
19K1 -
LIVE
Mally_Mouse
5 days agoFriend Friday!! 🎉 - Let's Play! - Gary's Mod!
46 watching -
LIVE
ZWOGs
9 hours ago🔴LIVE IN 1440p! - Resident Evil 3 First Playthrough, GMod w/ Mally_Mouse & Friends - Come Hang Out!
44 watching -
1:00:55
BonginoReport
8 hours agoJames Comey Indicted! - Nightly Scroll w/ Hayley Caronia (Ep.143)
143K110 -
1:20:26
Kim Iversen
6 hours agoThis Intel Analyst Has Accurately Predicted Putin's Every Move... Is War With NATO Next?
128K62