Python Forum

Full Version: input function question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I am going crazy and spent hours on this.
it seems my input function does not work.

I have a two line program

x = input()
print(x)
or

x = ('input something')
print(x)
and the program hangs on two seperate computers and prints nothing
What is going on here?

I feel really stupid.
How do you run your program?
(Jan-17-2022, 04:24 PM)deanhystad Wrote: [ -> ]How do you run your program?

I have tried interactive mode, i.e. command prompt and >>>> and also made a program using sublime.

Do I need to import a library ? I thouhjt input is a part of the language.
Do I need some sort of special terminator?
x = ('input something')
does not actually call the input function. Rather it assigns the text 'input something' to the variable x.

But again you should get some response. As Dean asked - how are you running this?
Do I need to append a line terminator character after I input x using x = input() ?

I have a simple file made in Sublime and compiled and run with the cntrl B command.
the programs hangs on the input statement. like I said , I tried this on two different computers and got the same result.

I am using python Ver 3.??
Try this and tell us what you get.
x = input ('Enter something now: ')
print (x)
correction input works in interactive mode.
I tried
x = input ('Enter something now: ')
print (x)
It prints
Output:
"enter something now"
and when i enter something thee is nothing.




and got no response.

Puzzling.
input() doesn't really work in interactive mode.

Next time someone asks how you are running your program, answer the question. "I am not running a program. I am running Python in interactive mode."
Actually, I did run python in interactive mode and the input function worked.

From the command line I entered "python" and saw the prompt >>>

>>> xx = input()
sdfddsf    I entered this
>>>> print(xx)   then I did...
sdfddsf     and the result is good
However...

x = input ('Enter something now: ')
print(x)
will not work
I see no reason why you would ever use input() in interactive mode. I guess it kind of works but it is really awkward.

If I do this in interactive mode it appears to work (awkwardly).
Output:
>>> x = input("A") Ahi >>> print(x) hi
I can also do this which is a bit less awkward.
Output:
>>> x = input("A"); print(x) Ahi hi
It would make a lot more sense to write:
Output:
>>> x = "hi" >>> print(x) hi
But you are right that you cannot paste two lines into an interactive session and have it work.
Output:
>>> x = input("A") Aprint(x) >>> hi Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'hi' is not defined
So what is the problem?
Pages: 1 2