+ 1
Not understanding if statement
help please
2 ответов
+ 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.