Sunday 6 March 2016

User Input example in Python

Every programming language has a way to accept user input. Like in Perl, you accept using STDIN. Similarly, Python interpreter has 2 inbuilt functions to read user input :

raw_input()
input()

Let's look into a simple python script which accepts user input and prints a statement.
Create a simple script - vi python_input.py

#!/usr/bin/python

name = raw_input('Please enter your name, visitor : ');

print ('Welcome to IroncladZone ' + name);

You see the variable "name" stores the input entered by the user. Accordingly we make use of this value in the next print statement.

Output :

./python_input.py

Please enter your name, visitor : Johnny

Welcome to IroncladZone Johnny

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker