+ 1

Help me, please with the loop

Hello. Can anybody help me with this question: How can I assign values to the variables in the loop? I mean, I want to get some variables like a1=..., a2=..., a3=..., a4=... in the loop (i from 1 to 4)?

3rd Oct 2017, 11:35 AM
Николай Митченко
Николай Митченко - avatar
5 Antworten
+ 3
Link your code here so people can see clearly what's the problem and offer solutions :)
3rd Oct 2017, 1:33 PM
Ipang
+ 1
for i in range(1,5): a[i] = i*i i will take the values from 1-4 so, a[i] means a[1] ... a[4] and then you can do the assignment
3rd Oct 2017, 11:44 AM
LayB
LayB - avatar
+ 1
Try creating an array.
3rd Oct 2017, 1:37 PM
Dragon Slayer Xavier
Dragon Slayer Xavier - avatar
0
i've tried,but there is an error: TypeError: 'str' object does not support item assignment
3rd Oct 2017, 11:53 AM
Николай Митченко
Николай Митченко - avatar
3rd Oct 2017, 1:42 PM
Николай Митченко
Николай Митченко - avatar