Conditional Statements

Python Programming Conditional Statements
9 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

Welcome back. So I think you remember, we have used the user defined input function in our previous video Today, we will be using that once again, along with that we will be using if so let's just start. So first I write, print. Hi. How are you? Now in the next line, I'm right.

See, here I use the input function. And I'm right. Please enter your choice. No one what I will do is here I will convert this input to integers, so we have already done it. So here are all converted through in function in C, and then I write I if condition. This is absolutely new to you all.

So if now I'll write d is equal to equal to one, give a semicolon. And in the next you've entered and in the next line, right, trained, you entered one. Now see this very carefully. What I've written here, I've written int, d equal to equal to here I've given double equal to sign, why? Because double equal to sign refers to equality, it will check the equality. If you enter here, one, then it will check here, whether you have entered one or any other different number.

So if you entered one Over here, it will match with D and then it will print you entered D. Now, remember here I have given a colon This is very important. Now, in the if condition you have to give a colon over here, now, whenever it will be take the colon here, it will execute the next day. Now, see the next print statement is not starting from the beginning, it is a little indented why, because, in this if condition after detecting a colon it will enter this statement. Otherwise if you provide a different statement after that, it will just overlook this one and it will enter to the next statement. Now, this print statement is associated with this if condition. So, here whenever I will write a Cologne, the next tip will always be indented like this.

So let us first execute the code and see what happens. So executed it is asking for a choice, I'm write one, and I'll enter. So you entered one came here. Now if I enter two here, what will happen? It print nothing, because I haven't provided any other statement to print if it is not equal to one, so it prints nothing. Now, let me slightly change this code.

So I'll just copy it and paste it over here and just slightly changing this code. I'm just removing this indentation and starting the print from the start. Now run this code see what happened. See, you get an error. See it also noted where the error is line fine. Print, see gives an ad over you expected an indented block because Here it is cologne.

So it means the next statement should start with indentation. So, give indentation now run this code and see it executed properly. So if I write one over here and press enter, it will print you waited one. Now, one more time, if I remove this column from here, what will happen? I'm removing this column. And now I'll execute this code once again.

See, it is showing you where the error is showing you line four, and then the error is over here. So it's showing the error, something is wrong over here. So it will always show you our error if you don't provide this column. So shift enter the correct one, and see you entered one. So now I will add few more statements to it. Let's see.

So first copy this code and paste it over here. Now have provided only one if condition. Now I want to provide one more condition to it. So now I'll after that, the print statement. I'll press enter Now see it is still in indented form. Now I want to come out from the if condition, and I'll provide one more condition to it.

So I will just give a backspace and click come out from the independent position. Now here I'll write again, I've conditioned that is Ed equal to equal to two, then a colon, again, it will come to the Indian in position, so print you entered to Okay. Now again, I want to provide one more condition. So give a Backspace, right. If D equal to equal to three colon, then right print. Now you're done right.

I am tired. You can drive Anything I drive untied. So if I execute this code now it will again asked me for the value to provide. So see now here I'll write one, you entered one again I will execute this code, I will try to see you entered to. Now again I'll execute this code, I write three, it print, I'm tired. So, what happened here is whenever you put a condition over here, and you provide a value, so it will first enter the first if condition it will check if it is true, it will print this statement.

If it is not true, it will come out from this statement and it will enter the next condition. Now it will check this if this is true, it will print the consecutive statement that is associated with it. Otherwise it will again come out from this condition and again it will enter the last condition. Now if it is true It will print this otherwise it will print nothing. Now here I provided only one condition for each, sorry, only one statement for each condition. So now I have to provide two statement.

For that. I'll just copy it and print it over here. Now, suppose I want to give a new statement to the first conditionality, that is if d equals equal to one. So here I will write. So print here I'll write you are doing well. Now execute this code it will ask you your choice.

So if I give one here, what it will do, it will enter this condition and it will perform this to statement it will perform both the statement because both the statement here is indented. And it means this book condition This both statement is under the first condition because it is indented. So provide your choice I'll write one and see what it do it print both the statement you entered one and you were doing well. So if you now provide another condition over here, suppose here I will provide one more condition or one more statement, you can see I'm saying condition that is not condition yet, I'm providing one more statement. So here and right, keep it up. Okay, now perform execute this code, it will again ask for your choice.

I'll give one and see it will execute the three statement. The first one it executes, you entered one, then it executed you are doing well. The third one it also executed Keep it up. So as many statement you want to provide under one condition you can provide So, this is the if condition we have started the if condition will again go in much detail of this if condition in our consecutive video. So see you in the next video till then keep practicing. 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.