mercredi 1 février 2017

Better way for nested if else

How can the nested if else can be done in a better way? I want to minimize code duplication for print "run dozer()"

print "some mechanical stuffs before this"
if a == 1:
    if b == 2:
        print "run car()"
    else:
        print "run dozer()"
else:
    print "run dozer()"
print "more mechanical stuffs after this"

Aucun commentaire:

Enregistrer un commentaire