Can anyone explain me what the difference between these two codes. Seems I don t understand the use of elif. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Can anyone explain me what the difference between these two codes. Seems I don t understand the use of elif.

num = 7 elif num == 5: print("Number is 5") elif num == 11: print("Number is 11") elif num == 7: print("Number is 7") else: print("Number isn't 5, 11 or 7") SECOND CODE: num = 7 if num == 5: print("Number is 5") if num == 11: print("Number is 11") if num == 7: print("Number is 7") else: print("Number isn't 5, 11 or 7")

30th Sep 2016, 10:05 PM
hernanoeh
1 Answer
+ 3
you start with if and than continue with elif, at the last one you put else :)
30th Sep 2016, 10:29 PM
Klodian Lula
Klodian Lula - avatar