Conditional statement (iff elif else)

Python Programming Conditional statement
11 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.22
List Price:  €93.18
You save:  €27.95
£56.04
List Price:  £80.07
You save:  £24.02
CA$96.09
List Price:  CA$137.28
You save:  CA$41.18
A$106.44
List Price:  A$152.07
You save:  A$45.62
S$94.93
List Price:  S$135.63
You save:  S$40.69
HK$547
List Price:  HK$781.46
You save:  HK$234.46
CHF 63.65
List Price:  CHF 90.94
You save:  CHF 27.28
NOK kr765.05
List Price:  NOK kr1,092.98
You save:  NOK kr327.92
DKK kr486.48
List Price:  DKK kr695
You save:  DKK kr208.52
NZ$116.68
List Price:  NZ$166.69
You save:  NZ$50.01
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,685.71
List Price:  ৳10,980.05
You save:  ৳3,294.34
₹5,844.71
List Price:  ₹8,349.95
You save:  ₹2,505.23
RM331.80
List Price:  RM474.03
You save:  RM142.22
₦98,423.43
List Price:  ₦140,610.93
You save:  ₦42,187.50
₨19,474.95
List Price:  ₨27,822.55
You save:  ₨8,347.60
฿2,584.73
List Price:  ฿3,692.63
You save:  ฿1,107.90
₺2,255.06
List Price:  ₺3,221.65
You save:  ₺966.59
B$356.31
List Price:  B$509.04
You save:  B$152.73
R1,298.99
List Price:  R1,855.78
You save:  R556.79
Лв127.57
List Price:  Лв182.26
You save:  Лв54.68
₩95,950.21
List Price:  ₩137,077.60
You save:  ₩41,127.39
₪261.40
List Price:  ₪373.45
You save:  ₪112.04
₱4,015.50
List Price:  ₱5,736.67
You save:  ₱1,721.17
¥10,912.42
List Price:  ¥15,589.84
You save:  ¥4,677.42
MX$1,187.01
List Price:  MX$1,695.81
You save:  MX$508.79
QR254.79
List Price:  QR364.01
You save:  QR109.21
P956.45
List Price:  P1,366.42
You save:  P409.96
KSh9,168.69
List Price:  KSh13,098.69
You save:  KSh3,930
E£3,313.80
List Price:  E£4,734.21
You save:  E£1,420.40
ብር4,020.93
List Price:  ብር5,744.43
You save:  ብር1,723.50
Kz58,536.36
List Price:  Kz83,626.96
You save:  Kz25,090.59
CLP$65,519.73
List Price:  CLP$93,603.63
You save:  CLP$28,083.90
CN¥505.79
List Price:  CN¥722.59
You save:  CN¥216.80
RD$4,064.05
List Price:  RD$5,806.04
You save:  RD$1,741.98
DA9,434.16
List Price:  DA13,477.95
You save:  DA4,043.79
FJ$159.43
List Price:  FJ$227.77
You save:  FJ$68.34
Q544.12
List Price:  Q777.35
You save:  Q233.22
GY$14,659.33
List Price:  GY$20,942.80
You save:  GY$6,283.47
ISK kr9,804.19
List Price:  ISK kr14,006.59
You save:  ISK kr4,202.40
DH702
List Price:  DH1,002.91
You save:  DH300.90
L1,236.68
List Price:  L1,766.77
You save:  L530.08
ден4,019.08
List Price:  ден5,741.79
You save:  ден1,722.70
MOP$563.89
List Price:  MOP$805.60
You save:  MOP$241.70
N$1,302.92
List Price:  N$1,861.40
You save:  N$558.47
C$2,577.98
List Price:  C$3,682.99
You save:  C$1,105
रु9,357.62
List Price:  रु13,368.60
You save:  रु4,010.98
S/260.83
List Price:  S/372.63
You save:  S/111.80
K271.34
List Price:  K387.65
You save:  K116.30
SAR262.49
List Price:  SAR375
You save:  SAR112.51
ZK1,913.50
List Price:  ZK2,733.69
You save:  ZK820.18
L324.50
List Price:  L463.60
You save:  L139.09
Kč1,630.34
List Price:  Kč2,329.15
You save:  Kč698.81
Ft25,331.89
List Price:  Ft36,189.97
You save:  Ft10,858.07
SEK kr764.93
List Price:  SEK kr1,092.80
You save:  SEK kr327.87
ARS$61,714.55
List Price:  ARS$88,167.42
You save:  ARS$26,452.87
Bs483.86
List Price:  Bs691.26
You save:  Bs207.40
COP$272,553.83
List Price:  COP$389,379.31
You save:  COP$116,825.47
₡35,845.57
List Price:  ₡51,210.15
You save:  ₡15,364.58
L1,730.57
List Price:  L2,472.36
You save:  L741.78
₲523,213.21
List Price:  ₲747,479.48
You save:  ₲224,266.27
$U2,704.33
List Price:  $U3,863.50
You save:  $U1,159.16
zł280.23
List Price:  zł400.34
You save:  zł120.11
Already have an account? Log In

Transcript

So today we will be starting with if else condition. So I have already started the if condition have showed you how to use the if condition and how if condition work now Today I'll show you how to use if else an Elif conditions. So for that, first I'll write is underscore male is equal to true, this is a logical operation, then is underscore dog is equal to true, then I will use the if condition. So if EAS underscore male, or is underscore, tall, then what to do print you are Or you are talk okay now else see I've written else from the beginning that is coming out from the if condition. So else print you are neither men nor you are taught okay. So here I've written is men equal to true install equal to true now I have given the condition if is male or Easter if anyone is true then it will print this if neither is true then it will pay in the end statement.

So run this code. So what it wrote what it print you are a male or you are tall because here in the if condition is.mil is equal to true ease underscore doll is equal to true So, both the condition here is true and in the if condition both the condition satisfied, so it printed the if condition okay now if I change it to false like this and the first one also I'm changing it to false like this. Now, if I run this code see what it print it printed the else condition you are neither male nor you are tall. So, in this way it check conditions and you can give conditions in this way and use the else statement also now is underscore men equal to true is underscore time equal to true sorry, right false expected. Now, remember, here I am writing true and false in this manner.

So firstly, letter of the true is t that is capital and first letter of the fourth is F, that is capital and you should maintain this syntax. So, if ease underscore Mel now I'll write and is underscore tall. Here I'm writing if both the condition is true or not, then print you are tall male, so there is a typing error. So you are a tall man now I'm right Elif s if so I'm giving one more condition over here and if is together called Elif, Elif is underscore men and not is underscore tall. So here what it will do if is underscore male is true and not is underscore tall is false. That means and not means is underscore tall should be false.

Now for this condition, it will print You are a short male now Elif ease underscore tall and not is underscore Mel then what it will do then it will print you are a tall female. Okay. And the last condition that we are giving there is not the condition basically I'm writing that else. If none of this is true, then print you are Short female Okay. Now if I run this code, it will first check the first condition that is the first if condition if it is true then it will print this one then if it is not true it will check the second condition then if the second condition is true, it will print the second statement. Now if this statement condition is also not true then it will enter this third one check the third condition if it is true then it will print this one and if all these three statements are not true, it we'll print the last statement that is your shot female.

Now check what it do okay so it printed you are shot male because what I've written here is is meant is true East all is false. So the second condition is matching. See E's LS is underscore male and not E's underscore total So this one is true and this one is false because I've written and not so, by default it is true as because I mentioned is and not that means this should be false. So, it printed the second condition you are a short male. Now, if you change the definition over here then the value will also default. So, if I change it to false and then run this what happens see it printed You are a short female, that is it printed the last condition last statement because all the above statement is not satisfied.

So it printed the last statement so I hope you're getting what this else if or Elif is doing so, let's move on to the next program. So, now, I will do a dir function I will use so now, this is function is basically a function where you need to define it when it will ask you. So def number def means define number then num one comma num two comma num three. If num one greater than or equal to num two and num one greater than equal to num three then what it will do? It will return now One know if, again I'm given a condition num two is greater than or equal to num three and now to greater than or equal to num one, then it will return num two. Okay.

S The last condition s, it will return num three. Then here, I have to mention this number over here. So basically here I need to write number and then we think they're the first bracket I have to mention the three numbers. So, here I mentioned 52 comma 21 comma 15 Okay. So, now, if I run this code, what it will do, it will consider these three numbers as number one number two and number three in the same way it is written now, it will take the first condition. So, after checking the first condition if the first condition both the conditions are true, then it will return num one that is it will return 52 Now, if the first condition is not true then it will enter the second one.

So, now it will check the second second conditions. So, there are two conditions in the second condition what We have provided Now, if this condition is true, then it will return num two that is 21. Now, if both the conditions are not true, then it will return num three that simply return 15. Now, let's run this code and see So, what it returned it returned 52 because num one is greater than num two obviously 52 is greater than 21 and num one is greater than equal to num three, obviously 52 is greater than 15. So it returned 52 because you have written return num one. Now if you change the value, suppose here I changed the value to two, comma nine comma six.

Okay, now run this code, see what returned, well it returned nine because the second condition here is true. Now two is greater than or equal to num three, num two is greater than or equal to num one. So nine is larger in all this three value, so it returned nine. So in this way, now if you just alter the values, and see now num trees, the greater one, so now if I run this code, it returns six. So in this way, if you change the value over here, it will give you different results. So in this way, you can define something and then you can give the value of that particular variable over here.

It will perform accordingly. So I'll be ending my video over here. I hope you understand today's concept of elsif and Elif, so keep practicing. See you in the next video. Thank you

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.