+ 1

Is there a way to simplify this code?

https://code.sololearn.com/ca4VU29bOmj7/?ref=app

28th Jul 2017, 7:54 AM
Daniel Robertson
Daniel Robertson - avatar
2 Respostas
+ 4
yes there is from random import randint x = randint(1,8) a=['sword', 'dagger', 'staff', 'sheild', 'headgear', 'chestplate', 'leggings'] y=a[x] print(y) or better from random import choice a=['sword','dagger','staff', 'shield','headgear','chestplate','leggings'] print(random.choice(a)) store them in array and then call them by index as python doesn't have switch.
28th Jul 2017, 8:05 AM
Sandeep Chatterjee
+ 3
import random options = ('sword','dagger','staff', 'shield', 'headgear','chestplate','leggings', 'boots') print(random.choice(options))
28th Jul 2017, 8:00 AM
richard