[英]system that applies the function to the index on loop?
I'm attempting to create a system where pre-defined variables are run through a function and placed in lists based on the value of the variable.我正在尝试创建一个系统,其中预定义的变量通过 function 运行并根据变量的值放置在列表中。
global i, st1, st2, st3, classa
A = []
B = []
st1 = '13'
st2 = '3'
st3 = '17'
list = [st1, st2, st3]
i = 0
while (i<2):
i = i + 1
a = list[i]
def listselect():
sn = 'student name-'
f = 'score-'
a = ()
if a in {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}:
A.append(sn+f+a)
elif a in {'10', '11', '12', '13', '14', '15', '16', '17', '18', '19'}:
B.append(sn+f+a)
print(A)
print(B)
listselect()
However it only outputs the empty lists, without the values being added.但是它只输出空列表,不添加值。
[]
[]
How would I be able to run this program on a while loop until all variables have been sorted?在对所有变量进行排序之前,我如何才能在 while 循环中运行该程序?
Sorry if anything is wrong with the post formatting, i'm new to the website.抱歉,如果帖子格式有任何问题,我是该网站的新手。
Does this do what you want?这会做你想要的吗?
st1 = '13'
st2 = '3'
st3 = '17'
A , B = [], []
a = list ([st1, st2, st3])
def listselect (a) :
sn = 'student name-'
f = 'score-'
for element in a :
if element in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') :
A.append (sn+f+element)
else : B.append (sn+f+element)
listselect (a)
print (A, '\n', B)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.