String literals must be terminated by the same sort of quoting that started them. Thus the "+Name1+" is interpreted as a literal part of your strings and passed on to c.execute(...) without the variable Name1 being inserted.
Thus both new columns would have the literal name +Name1+, which leads to the error message
sqlite3.OperationalError: duplicate column name: +Name1+
You probably wanted something like:
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('''CREATE TABLE TableName (Var1 REAL, Var2 REAL)''')
name1 = 'Test1'
c.execute('''ALTER TABLE TableName ADD COLUMN ''' + name1 + ''' INTEGER''')
name1 = 'Test2'
c.execute('''ALTER TABLE TableName ADD COLUMN ''' + name1 + ''' INTEGER''')
Rewritten with a loop, that'd be
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('''CREATE TABLE TableName (Var1 REAL, Var2 REAL)''')
for column_name in ['Test1', 'Test2']:
c.execute('''ALTER TABLE TableName ADD COLUMN ''' + column_name + ''' INTEGER''')
To avoid the risk of SQL injections, you shouldn't do string concatenation or manipulation on the SQL query or command, though. Instead use the parameter substitution Python's database API already offers:
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('''CREATE TABLE TableName (Var1 REAL, Var2 REAL)''')
for column_name in ['Test1', 'Test2']:
c.execute('''ALTER TABLE TableName ADD COLUMN ? INTEGER''', (column_name,))
In fact, the API will make an explicit loop unnecessary:
import sqlite3
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('''CREATE TABLE TableName (Var1 REAL, Var2 REAL)''')
column_names = [('Test1',), ('Test2',)]
c.executemany('''ALTER TABLE TableName ADD COLUMN ? INTEGER''', column_names)