python

User Input

Python provides built-in function for asking for user-input as below

#!/usr/bin/python

 raw_input("\nPress the enter key to exit.")

Here, “\n” is used to create new line before displaying the actual line. Once the user presses the key, the program ends. This can be used for getting the input from the user as below

>>> x=raw_input("enter the value")
 enter the value3
 >>> x
 '3'
 >>>

In the above example we see ‘3’ for variable x which user as inputted. You can provide space in raw_input just for readability purpose as below,

>>> x=raw_input("enter the value ")
enter the value 3
>>> x
'3'
>>>

Leave a Reply