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
SpartakusLIVE
1 hour ago#1 HERO of the PEOPLE || Ending the Week with FUN, WINS, and LAUGHS
126 watching -
LIVE
GritsGG
11 hours agoQuad Win Streaks!🫡 Most Wins in WORLD! 3600+
124 watching -
2:34:12
Spartan
3 hours agoScrims vs Mindfreak and then Ranked or another game idk
4.72K1 -
1:35:57
Roseanne Barr
5 hours agoEnd-Time Prophecies REVEALED: Jonathan Cahn’s Warning
142K54 -
1:08:58
vivafrei
6 hours agoComey INDICTED! Proof Jan. 6 was a FED-SURRECTION! Ostrich Crisis Getting More Attention & MORE!
153K102 -
LIVE
StevieTLIVE
2 hours agoBirthday Bash HYPE Warzone Wins ALL NIGHT
13 watching -
6:30:53
Dr Disrespect
8 hours ago🔴LIVE - DR DISRESPECT - ARENA BREAKOUT: INFINITE - STORM EVENT
181K9 -
3:35:23
Barry Cunningham
9 hours agoPRESIDENT TRUMP SPEAKS ON JAMES COMEY INDICTMENT! MORE TO COME! DELICIOUS LIBERAL MELTDOWNS!
79.3K45 -
25:59
Simply Bitcoin
1 day ago $2.42 earnedMichael Saylor Reveals $81T Bitcoin Plan to Cancel National Debt?!
46K9 -
1:33:51
Steve-O's Wild Ride! Podcast
1 day ago $2.00 earnedJohn C. Reilly's Surprising Connection To Jackass (And Beef With Weeman!)
61.1K11