mercredi 25 septembre 2019

Is it "wrong" to use a bunch of if's instead of elif's?

For the following code (Example), can I use if's instead of elif's? If I can, would it generate the same results, and also would it be considered as wrong to do so? Yes I know I can check myself but I don't want to mess up my actual code, because small errors ruin the entire program.

if (age > 5):
    print("hi")
if (age == 5):
    print("bye")
if (age < 5):
    print("cool")

Instead of

if (age > 5):
    print("hi")
elif (age == 5):
    print("bye")
elif (age < 5):
    print("cool")

Aucun commentaire:

Enregistrer un commentaire