In previous article we read about what is basics of python and what are data types in Python? Today I am going to learn that how to write a interactive & charming program by using input() & print() function.
In this article we learn about that how we take input data from the user & then display on the screen. Here we use mainly two function as
(i) Input()
(ii) Print()
(i) Input()
To get the user's input data simply we use input function. Example -
userName=input("Please Enter your Name:")
You asked from user that 'Please enter you name' user will entered self name. If you want to any other input from user you can find them from using the input function.
(ii) Print()
The print() function is used to display the information of users, which have entered by using the input function.
It accepts zero or more expressions as parameters, separated by commas.
Now you can use the print function such as
print("Hey There! My name is: ", userName)
Note - userName will print that value which value stored by the user in input() function.
Then after save the file and run the program you will find that a message will display on screen that (Please Enter Your Name:) suppose user entered his name Ram, then after press the enter button you will find this output that
Hey There! My name is Ram.
Read also - What are data types in Python?
A complete program by using input() & print() functions -
Here a complete program are given by using input() & print() function.
userName1 = input("Please enter your first name: ")
userName2 = input("Please enter your last name: ")
userAge = input("Please enter your age: ")
userCountry = input("Please enter your country name: ")
print("Hey! my name is", userName1, userName2, "and my age is", userAge, "& I am live in", userCountry, "." )
Save this code .py extension and run, you will find on the screen that
Please enter your first name: (suppose user entered his first name John) , after entered the first name press enter button next you will find that please enter your last name: (suppose user entered his last name Deo) after entered the last name press enter button again & you will found that please enter your age: (suppose user entered his age 25) , again after entered the age press enter button you will saw on the screen that please enter your country name: (suppose user entered his country name USA). Then press the enter button you will find the complete output as shown that -
Hey! my name is John Deo and my age is 25 & I am live in USA.
Read also - What is Python? Learn basics of Python?
Triple Quotes -
If you need to display a long message, you can use the triple-quote symbol (' ' 'or' ' ' ) to span your message over multiple lines.
Example -
print ('''Hello World.
My name is James and I am 20 years old.’’’)
Output of this code is
Hello World.
My name is James and I am 20 years old.
Conclusion -
I hope you will completely well known that how does work input() & output() function. In further series you will be find new resources of learning. So stay tuned with me. If you have any question you can ask me in comment.
0 Comments