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!
(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.
(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
(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.
(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
print
isn't used for reading input - it just prints the value and returns None
. Why aren't you using input
?!
You need to use input() rather than print().
x = int(input("enter some nmberu"))
print (x)
Output:
enter some nmberu5
5
(Feb-17-2020, 12:29 PM)darpInd Wrote: [ -> ]I have done as suggested
No you have not
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]](https://imagizer.imageshack.com/v2/xq90/923/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.