i'm just getting into programming and i've installed VScode and i've been using python 3.6. When i enter a simple code like:
print("Hello world!")
NAME = input("What's your name?")
print(NAME)
And when i run debug it appears the print Hello world! and the input "What's your name?" and i type whatever, and it doesn't print the NAME afterward.
Thank you in advance for the time taken to answer me.
please use IntegratedTerminal ratherthan internalTerminal
Maybe you can see it:
https://github.com/DonJayamanne/pythonVSCode/wiki/Capture-User-Input-via-input()-or-raw_input()
Related
I haven't really ran into many issues with python but I'm working on a side project and the input() function wasn't working. I created a new file to test out a simple input() function and the same thing happened, the program doesn't take any input and it instead seems to take in the pyenv version or something? Anyone know how to fix this?
# Taking input from the user
name = input("Enter your name")
# Print input
print("Hello", name)
Pasted output from terminal:
Enter your namepyenv shell 2.7.18
Hello pyenv shell 2.7.18
this question should be really simple, but since im a noob to python I have no idea what to do here.
the code that I sent was:
print("what is your name?")
name=input()
then this error would appear when I tried to run it:
name '(namethatwasinput)' is not defined
it worked before so i have no idea what's going on, can anyone help?
try using
name = input("what's your name: ")
I'm a complete newbie when it comes to coding, so I'm probably making a stupid mistake here. What I'm doing is following along with a Python For Beginners textbook and writing the 'Hello World' exercise. I added the variable 'name' to the code and called the variable in the very next line. However, the
print('Hello', name) line of code I wrote would not print, even though my first line print('Hello, world') did print. Here's a screenshot of the code run on the Python console There are no error codes, so I'm guessing I just incorrectly defined the variable, but I'm not sure.
You need to hit Enter after Python prints 'Keenan' to print the last line.
When you call input(str), str is the prompt. Once python prints the prompt, it's waiting for an input and then Enter.
So logically speaking your code should be:
name = input("What's your name?:")
print('Hello', name)
Which will print:
What's your name?:
where you can type:
What's your name?: Keenan
followed by Enter
I wrote a simply program:
print "What is your name?"
name = raw_input()
print "Hello %s!" % name
When I run it directly in VIM I get:
What is your name?
Hello print "What is your name?"!
I can't type anything. Program stops with "Hit any key to close this window..."
What is going here? Python 2.7, Win10, VIM 7.4.
I tried to write my first python program and I already get an error message. In the textbook introduction to computer science using python i found the following code:
name = input('What is your name? ')
print('Hello', name)
print('Welcome to Python!')
I checked multiple times for errors and I'm quite sure i typed it exactly like the textbook states. I saved the program as MyFirstProgram.py and after that i ran the module (by pressing F5). If i understand correctly the program asks you to fill in a name. So i typed 'John'. But when i did, the following error occurs:
Traceback (most recent call last):
File "C:/Users/Wout/.ipython/MyFirstProgram.py", line 3, in <module>
name = input('What is your name? ')
File "<string>", line 1, in <module>
NameError: name 'John' is not defined
Why is 'John' not defined? Isn't it the purpose of the program to enter any name? Why do i have to define it? I followed the instructions to the letter...
Kind regards
input, in Python 2, evaluates the input as if it were a snippet of Python code. This is almost never what you want. Use raw_input instead.
By the way, you're writing your code as if it were Python 3, but you appear to be using a Python 2 interpreter. If you run your code with Python 3, it will work fine (input in Python 3 is the same as raw_input in Python 2).
You should use raw_input() instead of an input(), since you are on python-2.x:
name = raw_input('What is your name? ')
print('Hello', name)
print('Welcome to Python!')
prints:
What is your name? John
('Hello', 'John')
Welcome to Python!
You are following a textbook for Python 3 but using Python 2. In Python 2, must use raw_input and don't need brackets on print statements.
'John' will work with input (John won't work), however you should use raw_input() like the others said