jeudi 19 mars 2020

How do I avoid walls of If statements? [duplicate]

I heard several times that coding like this is suboptimal:

if weapon == "sword":
 print("Knight") 
elif weapon == "katana":
 print("Samurai") 
elif weapon == "axe":
 print("Viking")

How do I write such code optimally?

Aucun commentaire:

Enregistrer un commentaire