4
    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')

When I run the code with the code runner extension the code shows in the terminal however when it gets to the input function it freezes like its asking me to input some data however I cant eve type a number or letter.

This is what the terminal shows...

[Running] python -u "c:\Users\bowen\Desktop\CSE 120\PROJECT 3\main.py"
Current Balance:  100
1. WITHDRAW
2. DEPOSIT
Select an option... 
Devin Bowen
  • 127
  • 1
  • 1
  • 13
  • 1
    "owever when it gets to the input function it freezes like its asking me to input some data however I cant eve type a number or letter." Please be specific. Did you try clicking the terminal window and pressing either the `1` key or the `2` key? When you do so, do you see the corresponding symbol? In general, do you see a blinking cursor in that window? Are you able to make the code run properly directly from the terminal? – Karl Knechtel Sep 15 '21 at 02:10

3 Answers3

12

Code Runner shows results in OUTPUT and doesn't accept inputs by default. Add

"code-runner.runInTerminal": true

in Settings.json, then you can input data.

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
9

ok i know what the problem is, it's not of python but of vscode, you have to enable one setting,

  1. do ctrl+, or just open settings
  2. search for code runner run in terminal
  3. enable it

thank me later :)

random_hooman
  • 1,660
  • 7
  • 23
  • welcome buddy ;) – random_hooman Sep 17 '21 at 05:43
  • I installed code runner, enable run in terminal and it still didn't work. My MWE was simply: x = input("Enter") . – Moti Feb 12 '23 at 07:43
  • To clarify: after editing I want to press F5 or ctrl-F5 and have the focus transferred to the terminal window without having to click there or ctrl-`. – Moti Feb 12 '23 at 13:09
  • This question is about changing a setting to allow code runner to run in terminal and not about pressing F5 to do so. But if you want to do that, go to your keyboard shortcuts and search for "code-runner.run" and change the default key to F5 or what you would like. – random_hooman Feb 12 '23 at 16:40
  • Sorry about the confusion. "code-runner.run" already has a shortcut ctrl-alt-N, but when I press that it runs the program but doesn't change the focus to the terminal window. I'll continue searching for a solution. – Moti Feb 13 '23 at 08:25
  • Solved! I unchecked "Code-runner: Preserve Focus" and the focus goes from the editor to the terminal. – Moti Feb 13 '23 at 16:20
3

Step-by-step:

  1. Click on extensions and make sure Code Runner is installed.
  2. Go to File > Preferences > Settings [Ctrl + ,]
  3. Type Code Runner in the search bar
  4. Scroll down and check on Code-runner: Run In Terminal

enter image description here