dimanche 19 mars 2017

Simpler If Statements

I have very little coding experience with Python, and am making a game for a Python coding class. I don't know any complicated stuff except this.

Is there a way to simplify the if statements from the code provided below to possibly one single if statement to reduce repetition? I have many more of these that will have to do many more rather than 4 numbers. Thanks.

import random
hero = random.randint(1,4)
if hero == 1:
    print 'Marth'
elif hero == 2:
    print 'Lucina'
elif hero == 3:
    print 'Robin'
else:
    print 'Tiki'

Aucun commentaire:

Enregistrer un commentaire