【发布时间】:2021-02-05 04:01:51
【问题描述】:
我正在尝试在 python 中创建一个小型数据库,该数据库最终将包含我感兴趣的大学的所有信息。我希望能够随时添加一所大学并向其中添加数据或获取数据远离我已经输入的数据。我想回答我在代码中输入的所有问题,然后将所有这些答案保存在数据库中。我现在有一些错误,任何帮助将不胜感激。谢谢!
import sqlite3
connection = sqlite3.connect("CollegeDB.db")
cursor = connection.cursor()
cursor.execute("CREATE TABLE Colleges (Name TEXT, Enrollment INTEGER, Location TEXT, Acceptance TEXT, Matriculation INTEGER, Testing TEXT, ACT INTEGER, SAT INTEGER, Tuition INTEGER, Scholarships TEXT, ApplicationDeadline BLOB, Visit? TEXT, Interview TEXT, Major TEXT, GreekLife INTEGER, ReligiousAffiliation TEXT)")
collegename1 = input("What is the name of the college?")
enrollment1 = input("What is the total number of undergrads?")
location1 = input("Where is it located?")
acceptance1 = float(input("What is the acceptance rate?"))
matriculation1 = int(input("What is the matriculation?"))
testing1 = input("Is testing optional?")
act1 = int(input("What is the minimum ACT score?"))
sat1 = int(input("What is the minimum SAT score?"))
tuition1 = int(input("What is the cost of tuition?"))
scholarship1 = input("Do they offer scholarships?")
applicationdeadline1 = input("What is the application deadline?")
visit1 = input("Have you visited?")
interview1 = input("Are interviews offered?")
major1 = input("What major interests you from this university?")
greeklife1 = int(input("What is the greek life percentage?"))
religiousaffiliation1 = input("Is there a religious affiliation?")
cursor.execute("INSERT INTO Colleges VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (
collegename1, enrollment1, location1, acceptance1, matriculation1, testing1, act1, sat1, tuition1, scholarship1,
applicationdeadline1, visit1, interview1, major1, greeklife1, religiousaffiliation1))
rows = cursor.execute("SELECT Name, Enrollment, Location, Acceptance, Matriculation, Testing, ACT, SAT, Tuition, "
"Scholarships, ApplicationDeadline, Visit?, Interview, Major, GreekLife, ReligiousAffiliation")
print(rows)
【问题讨论】:
-
您具体遇到了什么错误?另外,我知道您要做什么,但是您的具体问题是什么? (例如“这是我得到的错误:...,我该如何解决?”或“如何更新已添加到数据库中的行?”)。你的帖子很清楚,并且有一个代码示例,但你可以写一本关于你“想做”的事情的书。也许尝试为您的每个具体问题制作一个项目符号列表,将它们分解为非常具体的内容,以便我们可以通过清楚地回答每个问题来帮助您。也许阅读How do I ask a good question?
-
我收到一个语法错误,提示我运行它时它在信息附近。
-
可以编辑您的帖子并添加从终端复制的确切错误吗?
标签: python sql database sqlite