0
Can you somehow do this to variables? (variables embeded inside other variables)
As in: x= 1 n= 0 while x <= 10 x= 5x+2 print(x) x(n)= x #Litterally, what I want to do, is assign the value I get each time to a different variable... Is that possible? Btw, this code is purposefully incorrect, because I do not know how to 'do it'. x+= 1 n+= 1 #Then, is there a way to sum up all those variables created? print(sum(x(n))) Thank you everyone, I hope you understand what I mean, and can help me.
2 Antworten
+ 5
I think what you are looking for is a list, so you can pass multiple arguments to it. Try the following:
x = []
n = 0
while n <= 10:
x.append(n * 5 + 2)
print(x[n])
n += 1
print(x)
print(sum(x))
Is that what you meant?
0
Yes, near perfect. I’ve just read in to it, thanks.