I'm working on python program and i want something like this:
for i in range(1,n+1):
var(a+str(i)) = input()
#do something
So that variables are a1,a2,a3,etc. Can this be done, and how?
You don't want to do that, trust me. You want to use a dictionary
vars = {}
for i in range(1,n+1):
vars[i] = input()
#do something
or, since all the numbers are sequential in your special case, a list:
vars = [None] # initialize vars[0] with None
for i in range(n):
vars.append(input())
#do something
Now you can access your variables like vars[2], vars[5] etc.
vars is a terrible name for a variable - you should use a meaningful name instead. This is just meant as an example.)
range(1,n+1)instead ofrange(n)should alert you to the fact that you're doing something wrong.