+ 1
Is there a way to simplify this code?
2 odpowiedzi
+ 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.
+ 3
import random
options = ('sword','dagger','staff', 'shield',
'headgear','chestplate','leggings',
'boots')
print(random.choice(options))