【问题标题】:Python Input function not Working in VS CodePython 输入函数在 VS Code 中不起作用
【发布时间】:2021-11-10 03:23:14
【问题描述】:
    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')

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

这是终端显示的内容...

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

【问题讨论】:

  • “但是当它到达输入功能时它会冻结,就像它要求我输入一些数据但是我不能输入数字或字母。”请具体。您是否尝试单击终端窗口并按下1 键或2 键?当你这样做时,你看到相应的符号了吗?通常,您是否在该窗口中看到闪烁的光标?能直接从终端让代码正常运行吗?

标签: python visual-studio-code input terminal vscode-code-runner


【解决方案1】:

好的,我知道问题出在哪里,不是python而是vscode,你必须启用一个设置,

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

稍后谢谢我:)

【讨论】:

  • 欢迎好友 ;)
【解决方案2】:

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

"code-runner.runInTerminal": true

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

【讨论】:

  • @DevinBowen。不客气。快乐编码:)
猜你喜欢
  • 2022-01-13
  • 2017-12-18
  • 1970-01-01
  • 1970-01-01
  • 2018-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
相关资源
最近更新 更多