我对Python的编码经验非常少,而且正在为Python编码类制作游戏.除了这个,我不知道任何复杂的东西.
有没有办法简化下面提供的代码中的if语句,可能只有一个if语句来减少重复?我有更多的这些将需要做更多而不是4个数字.谢谢.
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'
Run Code Online (Sandbox Code Playgroud)