if statements in Python - making programs smarter
What is an 'if'?
It is a condition.
If I am thirsty
I drink water
If I am moody
I listen to music
These are some examples that show us how and where an 'if' works in normal languages.
The above specified us doing certain things if the condition is true. What if the condition was false, then we move on to the next one that is true.
For example :
I am at a snack bar
if I want a small bite
I order a samosa
otherwise if I want a mini lunch
I order vada paav
otherwise I order bhelpuri
(samosa, vada paav and bhel puri are north Indian snacks)
Now look closely at the screenshots which show examples of True and false
True
False
Nothing is printed because the statement is false.
Else statement
Else just means otherwise
What if we used the else statement?
See what happens
What if we use an 'or' in between to specify one or more conditions? we need to just write the 'or' condition. Work it out with many examples to understand it. it really is easy to grasp.
and what if we write the statements are false
and
The next condition is 'and'
Look at the screenshots below to understand and play with the code
and false
All images are screenshots of work done on colab.
Congratulations @filler! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
To support your work, I also upvoted your post!
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!