发布输入数据,python

时间:2018-08-08 17:48:09

标签: python database sqlite

所以我正在为一个学校项目工作,我已经创建了数据库并正在工作,我已经以传统的方式在插入语句中输入了数据,然后再输入数据,现在我正尝试获取它这样我的用户就可以输入数据了。我得到的错误是,它不会让用户输入第一个问题的数据。

import sqlite3
conn = sqlite3.connect('agile.db')
c = conn.cursor()[enter image description here][1]
story1 = str(input("What is your story? "))
points1 = int(input("How many points is this story? "))
done1 = input('Is your task complete? ')
x = '''INSERT INTO stories(story, points, done) VALUES (?, ?, ?));'''
c.execute(x,(story1, points1, done1,))
conn.commit()

下图显示了错误:

img

2 个答案:

答案 0 :(得分:0)

根据您的代码,并且您说它在第一个输入中出错,这可能与您键入字符串的方式有关。

尝试一下

import sqlite3

conn = sqlite3.connect('agile.db')

c = conn.cursor()

#May want to add functionality to verify data type
story1 = input("What is your story? ")

#May want to add functionality to verify data type
points1 = input("How many points is this story? ")

#May want to add functionality to verify data type
done1 = input('Is your task complete? ')


sql_cmd = 'INSERT INTO stories(story, points, done) VALUES ({}, {}, {});'.format(story1, points1, done1)
c.execute(sql_cmd)

conn.commit()

答案 1 :(得分:0)

我刚刚运行了您的代码,对我来说一切似乎都正常(至少对于前两个问题而言) 我认为问题出在您的python安装上。您使用的是哪个版本?