input function question - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: input function question (/thread-36110.html) Pages:
1
2
|
input function question - barryjo - Jan-17-2022 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. RE: input function question - deanhystad - Jan-17-2022 How do you run your program? RE: input function question - barryjo - Jan-17-2022 (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? RE: input function question - jefsummers - Jan-17-2022 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? RE: input function question - barryjo - Jan-17-2022 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.?? RE: input function question - BashBedlam - Jan-17-2022 Try this and tell us what you get. x = input ('Enter something now: ') print (x) RE: input function question - barryjo - Jan-17-2022 correction input works in interactive mode. I tried x = input ('Enter something now: ') print (x)It prints and when i enter something thee is nothing.and got no response. Puzzling. RE: input function question - deanhystad - Jan-17-2022 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." RE: input function question - barryjo - Jan-17-2022 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 goodHowever... x = input ('Enter something now: ') print(x)will not work RE: input function question - deanhystad - Jan-17-2022 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). I can also do this which is a bit less awkward. It would make a lot more sense to write: But you are right that you cannot paste two lines into an interactive session and have it work. So what is the problem?
|