我希望程序向用户询问信息(即年龄和姓名),并将该信息放入数据库中。
我尝试了以下方法:
import sqlite3
connection = sqlite3.connect("Students.db")
cursor = connection.cursor()
sql_command = """
CREATE TABLE age_name (
age INTEGER PRIMARY KEY,
name VARCHAR(50));"""
cursor.execute(sql_command)
for s in range(0,20):
student_name=input('Students Name: ')
student_age=input(' Students Age: ')
new_data = ("""INSERT INTO age_name (student_age, student_name)
VALUES ({},{});""".format(age,name))
cursor.execute(new_data)
不断出现的错误是:
cursor.execute(new_data)
OperationalError: no such column: 'James'
我有Python 3.7,并且在spyder中工作。