42. Learning If Else in Python (Day 38)

42. Learning If Else in Python (Day 38)

Today's lecture was a full immersion in Python Conditions and If statements. Reminded me of maths in school! In case you forgot, it's these:

\= (equal to), > (greater than), < (less than)
a= b
b< c
c > d

How the if works in Python is:

a = 500 b = 200 if a > b: print("a is greater")

Print is used for giving an output. So, if we run those commands, you will get a result, in this case, "a is greater".

The elif

This word is a short form for "Else if", which basically means - if a previous condition was false, then try another condition.

a = 500 b = 200 if a > b: print("a is greater")
elif a = b:
print("They are equals!")

The else

This one is used if anything is outside of the previous conditions, or if it didn't meet any of the previous conditions.

a = 500 b = 200 if a > b: print("a is greater")
elif a = b:
print("They are equals!")
else:
print("b is greater")

Conclusion

So far so good. I understand the theory of the above, but I need a lot of practice! I asked the tutor if there were any websites that offer practice challenges and he referred me to the below two:

https://leetcode.com/

https://www.codewars.com/

They look great! This is exactly what I need to sharpen my coding skills and be more confident! I just need to find the time to do them though :( Perhaps, during my Christmas-New Year break coming up!

Time now - 10:25 and good night. It's drizzling out there.