Ner*_*ual 0 python function conditional-statements
我正在尝试学习 python,并且刚刚了解了条件语句,并且正在努力创建自己的函数。
您介意告诉我我做错了什么吗?我必须在最后编写复杂的打印语句来一一调用我的所有函数?
此外,任何风格提示也将不胜感激。
预先感谢您可以提供的任何信息。
import random
#VARIABLES
topChamps = ['Nasus', 'Garen', 'Nautilus']
botChamps = ['Draven', 'Caitlyn', 'Jhin']
midChamps = ['Lux', 'Veigar', 'Karthus']
supChamps = ['Sona', 'Tahm Kench', 'Alistar']
jgChamps = ['Amumu', 'Rammus', 'Malphite']
selectNum = 0
roleNum = 0
champArr = []
champ = "wrong"
role = str(input("what role did you get? "))
#function to make the role choice easier for computer to read
def roleChoose():
if role == "top":
roleNum = 1
elif role == "bot":
roleNum = 2
elif role == "mid":
roleNum = 3
elif role == "sup":
roleNum = 4
elif role == "jg":
roleNum = 5
return roleNum
#function that determines what role list to use for champion choice
def arrayGrab(Num):
if Num == 1:
champArr = topChamps
elif Num == 2:
champArr = botChamps
elif Num == 3:
champArr = midChamps
elif Num == 4:
champArr = supChamps
elif Num == 5:
champArr = jgChamps
return champArr
print("made it to the end but you messed up")
#function that pulls a random name from champ list
def charSelect(arr):
x = random.randrange(0,2)
champ = arr[x]
return champ
print(charSelect(arrayGrab(roleChoose())))
Run Code Online (Sandbox Code Playgroud)
IIUC,你可以像这样取消打印:
role = roleChoose()
grab = arrayGrab(role)
char = charSelect(grab)
print(char)
Run Code Online (Sandbox Code Playgroud)
在赋值的左侧使用您喜欢的任何变量名称。