Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input function question
#1
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.
Yoriz write Jan-17-2022, 07:19 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
How do you run your program?
Reply
#3
(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?
Reply
#4
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?
BashBedlam and ndc85430 like this post
Reply
#5
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.??
Reply
#6
Try this and tell us what you get.
x = input ('Enter something now: ')
print (x)
Reply
#7
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.
Reply
#8
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."
Reply
#9
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
Reply
#10
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 928 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  Question on dir() function Soorya25 1 1,107 Jan-16-2023, 09:33 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,026 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Function not scriptable: Noob question kaega2 3 1,134 Aug-21-2022, 04:37 PM
Last Post: kaega2
  Showing an empty chart, then input data via function kgall89 0 943 Jun-02-2022, 01:53 AM
Last Post: kgall89
  function with 'self' input parameter errors out with and without 'self' called dford 12 2,995 Jan-15-2022, 06:07 PM
Last Post: deanhystad
Big Grin General programming question (input string)[ jamie_01 2 1,569 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Problem with input after function luilong 10 4,019 Dec-04-2021, 12:16 AM
Last Post: luilong
  Exit function from nested function based on user input Turtle 5 2,858 Oct-10-2021, 12:55 AM
Last Post: Turtle
Star I'm getting syntax error while using input function in def. yecktmpmbyrv 1 1,932 Oct-06-2021, 09:39 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020