此错误使我无法继续进行我的项目,即使删除了几乎所有内容,我似乎也无法弄清楚它是否会运行。
我尝试删除不必要的代码并删除了一些偶然的功能。
import sqlite3
with sqlite3.connect("Cpus.db") as connection:
print(connection)
c = connection.cursor()
def create_entry(connection):
c = connection.cursor()
tables = ["Cpus", "Cores", "Manufactures", "Sockets"]
print(tables)
tables_display = input("What Table Do Want To Make An Entry Too? ")
append_table_cpu = input("What Is The Name Of Your Cpu You Are Adding? ")
append_table_cost = input("How Much Does The Cpu You Are Adding Cost? ")
append_table_speed = input("How Fast Is The Cpu That You Are Adding?, Write Like This 2.00GHz")
append_table_cores = input("How Many Cores Does Your Cpu Have? ")
append_table_threads = input("How Many Threads Does The Cpu You Are Adding Have? ")
append_table_socket = input("What Type Of Socket Does Your Cpu Use? ")
tuple_insert = (tables_display, append_table_cpu, append_table_cost, append_table_speed, append_table_cores, append_table_threads, append_table_socket)
sql_query = ("INSERT INTO (Name,Cost,Speed_GHz,Cores,Threads,Socket) VALUES (?,?,?,?,?,?,?)")
c.execute(sql_query,tuple_insert)
results = c.fetchall()
for i in results:
print("Id: Manufactures: ".format(i[0],i[1]))
try:
while True: #Puts Everything In A Loop
option_1 = int(input("What Would You Like To Do To The Cpu Database, 1) Make An Entry, 2) Read The Data Or 3) Delete Data. Type 1, 2, ,3 "))
if option_1 == "1":
create_entry()
else:
print("Please Type A Valid Reply")
我希望它能够运行,但是无论我尝试什么,都会显示相同的错误。
答案 0 :(得分:0)
try
的原因必须总是 ,后接至少一个except
子句。
# ILLEGAL CODE
try:
print("hello world")
以下是正确代码的示例:
# OKAY CODE
try:
print("hello world")
except ValueError as exc:
pass
出现错误的原因是在尝试捕获块完成之前 。
try:
while True: #Puts Everything In A Loop
option_1 = int(input("What Would You Like To Do To The Cpu Database, 1) Make An Entry, 2) Read The Data Or 3) Delete Data. Type 1, 2, ,3 "))
if option_1 == "1":
create_entry()
else:
print("Please Type A Valid Reply")
# MISSING `EXCEPT`!!!!!!
如果在文件末尾留下任何其他未完成的语句,则会出现相同的错误。例如,如果您写的x =
没有右侧,那么解释器将意外遇到文件结尾(EOF)。会在填写赋值语句右侧的 之前遇到EOF。