student1=[80,80,90]
student2=[70,40,50]
...
student30=[40,50,70]
Classroom=[student1,student2,....,student30]
When there are only n student lists, I want to put all of these elements in the Classroom list, which function should I use? I'm Python New B. I was searching, but the code wasn't made as I thought, so I'm asking you a question.
python
I think there's something important missing from the question.
through a repetitive sentence I think you want to put the student in the classroom list.
Exactly what you want or... If you don't reveal the blocked part after proceeding
It's hard to get an accurate answer. I don't know if the intention of the question is correct, but please refer to the
q1 = [1,2,3]
q2 = [2,3,4]
q3 = [1,6,7]
r = []
for i in range(1,4):
s = q+str(i)
r.append(locals()[s])
print (r)
#[[1, 2, 3], [2, 3, 4], [1, 6, 7]]
I had a similar thought a long time ago.
To answer first.
There is a way to do what you want. But it's not that desirable, it's not the usual way.
Think it over.
For now, the appropriate answer to your wishes is as follows, but it is not a common situation. Do I really need to do this once? I think it'd be good to think about it carefully.
student1=[80,80,90]
student2=[70,40,50]
student3=[40,50,70]
class_room = []
for i in range(1,4):
exe_str = f"class_room.append(student{i})"
eval(exe_str)
print(class_room)
What the hell am I working on this code for?
Do we really need this code?
Another better way. Wouldn't there be a more general way? Is this really necessary?
I think you need to think about that
© 2024 OneMinuteCode. All rights reserved.