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

VS Code使用Code Runner运行Python时input函数无法正常输入问题

问题解决方法

1. 修复Code Runner无法输入的配置问题

  • 打开VS Code设置界面,搜索code-runner.runInTerminal选项,勾选该配置项,强制Code Runner在可交互的集成终端中执行代码,而非默认的只读输出面板。
  • 配置修改完成后重新运行代码,即可在终端正常输入内容。

2. 修复代码逻辑错误

input()函数的返回值固定为字符串类型,现有代码直接将输入结果和整数1、2做相等判断,永远会进入else分支,需要调整判断条件:

balance = 100
print('Current Balance: ', balance)
while balance > 0:
    print('1. WITHDRAW')
    print('2. DEPOSIT')
    choice = input("Select an option... ")
    if choice == '1':
        print('1')
    elif choice == '2':
        print('2')
    else:
        print('test')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 16:48:01