You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CS50 Finance项目buy函数执行时报RuntimeError: incomplete input错误

错误原因

你遇到的RuntimeError: incomplete input报错是SQL语法不完整导致的。查看你的INSERT语句可以发现,VALUES子句后的括号仅输入了左半部分,没有对应的右闭合括号,SQL解析器无法识别完整的合法语句,因此抛出输入不完整的错误。
出错的代码段如下:

db.execute("INSERT INTO transactions (user_id, name, shares, price, type, symbol) VALUES ( ?, ?, ?, ?, ?, ?",
            user_id, stock_name, shares, stock_price, 'buy', symbol)

注意语句中VALUES ( ?, ?, ?, ?, ?, ?末尾缺失了右括号)。

解决方法

只需要给上述INSERT语句的VALUES子句补上缺失的右括号即可,修改后的代码如下:

db.execute("INSERT INTO transactions (user_id, name, shares, price, type, symbol) VALUES ( ?, ?, ?, ?, ?, ?)",
            user_id, stock_name, shares, stock_price, 'buy', symbol)

修改后重新运行即可正常完成下单逻辑。

内容的提问来源于stack exchange,提问作者thecalendar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 17:06:05