Issue
VS Code does not shows the input given in the Jupyter Notebook, just the output. I want to save my Jupyter Notebooks with the input given also i.e. inline input, to improve readability.
VS Code not showing what was given as input
The Jupyter Server does this, but I prefer VS Code for the aesthetic reasons and code completion and better integration with Git.
Jupyter Notebook server also showing the input given,(What I want to have, unlike VS Code)
Is there any way to also have the input provided below the code cell in VS Code?
I tried looking into the settings and can't find one addressing this.
I also referred to this link: Jupyter Notebooks in VS Code
A previous question regarding this( ~ 3 years ago): Show question/input in vscode jupyter notebook output
Solution
the correct way to achieve this is with an explicit print
statement as opposed to relying on the default behaviour of any given editor.
I would also argue that the behaviour of VScode is more consistent in the sense that i do not want to see a number unless i specifically request it with a print statement !
So this is what i would expect to do:
n = int(input())
print(f'there are {n} stars.')
i = 1
while i <= n:
spaces = 1
while spaces <= n - i:
print(' ', end='')
spaces = spaces + 1
stars = 1
while stars <= i:
print('*', end='')
stars = stars + 1
print()
i += 1
And this is the output:
there are 4 stars.
*
**
***
****
having said this, the jupyter notebook in vscode does provision for the fact that the last variable in the cell is printed. so if you wanted to see the value of n, then you could make the last line of code n
...
Answered By - D.L
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.