+ 1

Not understanding if statement

help please

5th Sep 2018, 2:12 PM
preethu
preethu - avatar
2 Answers
+ 2
We useĀ if statementsĀ in our everyday life all the time – even if our everyday life is not written in Python.Ā IfĀ the light is greenĀ thenĀ I’ll cross the road;Ā otherwiseĀ I’ll wait.Ā IfĀ the sunĀ is upĀ thenĀ I’ll get out of bed;Ā otherwiseĀ I’ll go back to sleep. Okay, maybe it’s not this direct, but when we take actions based on conditions, our brain does what a computer would do: evaluate the conditions and act upon the results. Well, a computer script doesn’t have a subconscious mind, so for practice for computer programming we have to understand how an if statement works and how we can apply it in Python! Let’s say we have two values:Ā a = 10 andĀ b = 20. We compare these two values:Ā a == b. This comparison has either aĀ TrueĀ or aĀ FalseĀ output. We can go even further and set a condition:Ā if a == bĀ isĀ TrueĀ then we printĀ 'yes'. If it’sĀ FalseĀ then we printĀ 'no'. And that’s it, this is the logic of the Python if statements.
5th Sep 2018, 4:24 PM
Maninder $ingh
Maninder $ingh - avatar