0

I was learning python as a beginner through YouTube. In the video I was following the output was shown in terminal, but not in my case. It doesn't even accept taking in data for the variable. What am I doing wrong?

the code was simply :

a = input("Enter name")
print(a)

but the output would only show the text, but wont let me type the input

matszwecja
  • 6,357
  • 2
  • 10
  • 17
  • 2
    Please don't post code as screenshots, please copy and paste into the question as text – Emi OB Nov 16 '22 at 12:37
  • 1
    just type something in terminal and then hit enter – sahasrara62 Nov 16 '22 at 12:41
  • how are you running your code? are you using an IDE or are you calling your program from the terminal? – Sembei Norimaki Nov 16 '22 at 12:44
  • @sahasrara62 i tried to input the txt "hello", but it threw some error, hello : The term 'hello' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + hello + ~~~~~ + CategoryInfo : ObjectNotFound: (hello:String) [], CommandNotF oundException + FullyQualifiedErrorId : CommandNotFoundException – Suyan Shrestha Nov 16 '22 at 12:44
  • assuming you have your code saved in a file named `myfile.py` and that you have a terminal open: go to the folder where you have your program and type `python myfile.py` to execute your program. You will see the text "Enter name" then just introduce a name and press enter – Sembei Norimaki Nov 16 '22 at 12:45
  • @SembeiNorimaki i m using vscode as ide, not through terminal – Suyan Shrestha Nov 16 '22 at 12:45
  • what extension are you using to run python inside vscode? if ou are using coderunner take a look at https://stackoverflow.com/questions/69186311/python-input-function-not-working-in-vs-code – Sembei Norimaki Nov 16 '22 at 12:47

2 Answers2

0

You code should be working fine. Maybe, you are trying to edit the text Enter name, which is not possible in the terminal.

Try typing the name and pressing <Enter> when the text Enter name shows up.

You can test it here: https://pythonsandbox.com/code/pythonsandbox_u20054_20A4kkNBC961W5aZFb2NJCBW_v0.py But keep in mind that this is running on the web, not in a terminal, so it will show an input box in which you can input the data.

notrev
  • 665
  • 1
  • 5
  • 16
  • 1
    just found out the path pointed out to a directory in C: , but my file was in drive D:...thnx for the recommending me the sandbox site tho – Suyan Shrestha Nov 17 '22 at 03:24
0

Firstly, please ensure that you installed Python extension.

Then you can run the file by click Run Python File button.

enter image description here

If you install the code-runner extension and use Run Code button. You need to add the following code to your settings.json (shortcuts "Ctrl+shift+P" and type Preferences : Open User Settings):

"code-runner.runInTerminal": true,

By the way, read docs is a good choice.

MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13