Python Forum
Input() function not working in VS Code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Input() function not working in VS Code
#1
I am new to programming -- just doing simple hand-on and input function is not working in VS Code (Anaconda). just tried same thing in Juptyr notebook and it responds as expected.
1st Code with issues
replicating part of code:
import sys
print ("enter your name ")
x= input ()
print ("hello  ", x)
## This is asking for input and printing correct result in Jupyter notebook--
while same is giving no results in VS code - below is the snippet I get in output terminal after I execute these statement:
Output:
enter your name >>> x= input () print ("hello ", x)
## It is not asking me to enter the name##

2nd Code with issues
r = int (input ("enter a number"))
print (r*2)
giving correct output in Jupyter
while same is throwing error in VS Code:
r = int (input ("enter a number"))
print (r**2)
Error:
Error: Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: 'print (r**2)' >>>
Please support to resolve, TIA!
Reply
#2
(Feb-16-2020, 03:57 PM)darpInd Wrote: while same is giving no results in VS code - below is the snippet I get in output terminal after I execute these statement:
In setting search code-runner.runInTerminal set to True.
More tips here VS Code from start,i to do also mention this in tutorial.
Reply
#3
(Feb-16-2020, 04:36 PM)snippsat Wrote:
(Feb-16-2020, 03:57 PM)darpInd Wrote: while same is giving no results in VS code - below is the snippet I get in output terminal after I execute these statement:
In setting search code-runner.runInTerminal set to True.
More tips here VS Code from start,i to do also mention this in tutorial.

sorry couldn't find this code-runner.runInTerminal . I tried in File --> prefrences--> setting __> search.. but this flag code-runner.runInTerminal is not available
Reply
#4
(Feb-16-2020, 05:46 PM)darpInd Wrote: sorry couldn't find this code-runner.runInTerminal . I tried in File --> prefrences--> setting __> search.. but this flag code-runner.runInTerminal is not available
Yes i forget to mention that's a feature of Code Runner.
You should install it,also get a button for running code.
Also look a tutorial and set in code-runner.executorMap:
"python": "$pythonPath $fullFileName",
This make it always follow current Python interpreter,that's active down in left corner.
Reply
#5
(Feb-16-2020, 10:41 PM)snippsat Wrote:
(Feb-16-2020, 05:46 PM)darpInd Wrote: sorry couldn't find this code-runner.runInTerminal . I tried in File --> prefrences--> setting __> search.. but this flag code-runner.runInTerminal is not available
Yes i forget to mention that's a feature of Code Runner.
You should install it,also get a button for running code.
Also look a tutorial and set in code-runner.executorMap:
"python": "$pythonPath $fullFileName",
This make it always follow current Python interpreter,that's active down in left corner.

I have done as suggested

{
"files.autoSave": "afterDelay",
"python.dataScience.sendSelectionToInteractiveWindow": true,
"python.pythonPath": "C:\\ProgramData\\Anaconda3",
"code-runner.runInTerminal": true
}


after that-- just compiled below simple code and getting the below results again.. it is publishing 'none'.. while it has not asked any value from me

x = print("enter something")
print (x)
Error:
>>> x = print("enter something") enter something >>> print (x) None
See this -- providing error.. not sure what is happening.
x = int(print("enter some nmberu"))
print (x)
Error:
>>> x = int(print("enter some nmberu")) enter some nmberu Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' >>> print (x) None
Reply
#6
print isn't used for reading input - it just prints the value and returns None. Why aren't you using input?!
Reply
#7
You need to use input() rather than print().

x = int(input("enter some nmberu"))
print (x)
Output:
enter some nmberu5 5
Reply
#8
(Feb-17-2020, 12:29 PM)darpInd Wrote: I have done as suggested
No you have not Wink
They change as was talking about was in code-runner.executorMap as in my tutorial.
Also between perl and php.
"php": "php",
"python": "$pythonPath $fullFileName",
"perl": "perl",
As mention now in last code use use print().
Your first code was:
r = int(input("enter a number: "))
print(r**2)
I can use Anaconda as demo as you use,the point now is that now if change Python interpreter,
all running of code will use that Python interpreter(down in left corner).

[Image: hwDKtM.png]
So now running code as a script an can type input in Terminal,
In interact interpreter it will be like this(enter after each line).
λ ptpython
>>> r = int(input("enter a number: "))
enter a number: 55
>>> r**2
3025
I use ptpython,but you can use eg IPython or JupyterLab which is the Browser version with a lot of features.
You just have to find a setup that work for you,as all of this can be confusing in the start.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Excel isnt working properly after python function is started IchNar 3 215 Yesterday, 10:27 AM
Last Post: lillydalson
  difference between forms of input a list to function akbarza 6 1,100 Feb-21-2024, 08:02 PM
Last Post: bterwijn
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 1,085 Aug-31-2023, 05:36 PM
Last Post: deanhystad
Shocked kindly support with this dropna function not working gheevarpaulosejobs 2 702 Jul-24-2023, 03:41 PM
Last Post: deanhystad
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 984 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 920 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,130 Dec-25-2022, 03:00 PM
Last Post: askfriends
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,035 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
  Code won't break While loop or go back to the input? MrKnd94 2 983 Oct-26-2022, 10:10 AM
Last Post: Larz60+
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,103 Oct-13-2022, 08:09 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020