Python 输入函数在 VS Code 中不起作用

Dev*_*wen 8 python terminal input visual-studio-code vscode-code-runner

    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')
Run Code Online (Sandbox Code Playgroud)

当我使用代码运行程序扩展运行代码时,代码显示在终端中,但是当它到达输入函数时,它会冻结,就像要求我输入一些数据一样,但我无法输入数字或字母。

这是终端显示的...

[Running] python -u "c:\Users\bowen\Desktop\CSE 120\PROJECT 3\main.py"
Current Balance:  100
1. WITHDRAW
2. DEPOSIT
Select an option... 
Run Code Online (Sandbox Code Playgroud)

Mol*_*SFT 16

Code Runner在 OUTPUT 中显示结果,默认情况下不接受输入。添加

"code-runner.runInTerminal": true
Run Code Online (Sandbox Code Playgroud)

在Settings.json中,就可以输入数据了。


PYC*_*PYC 11

问题不是 python 而是 vscode,你必须启用一项设置,

  1. 执行ctrl+,或仅打开设置
  2. 搜索在终端中运行的代码运行程序
  3. 启用它


小智 7

一步步:

  1. 单击扩展并确保Code Runner已安装。
  2. 转到文件 > 首选项 > 设置[ Ctrl+ ,]
  3. Code Runner搜索栏中输入
  4. 向下滚动并检查Code-runner: Run In Terminal

在此输入图像描述

  • 这不是只是下面 random_hooman 的答案的复制粘贴吗?顺便说一句,日期自 2021 年 9 月 15 日起 (2认同)