Python Program To Take Input From User

Python Program To Take Input From User

In this tutorial, you will learn to write a Python Program To Take Input From User.

You can use the built-in input() function to take the input from the user.

The input() function in Python is used to take input from the user.

It reads a line of text from the standard input (usually the keyboard) and returns the text as a string.

The syntax of the input() function is as follows:

input(prompt)

Where the prompt is an optional string argument that is displayed to the user before taking input.

When the input() function is called, the program waits for the user to enter input.

Once the user enters the input and presses the Enter key, the input() function reads the input and returns it as a string.

Python Program To Take Input From User

name = input("Enter your name: ")
print("Hello, " + name + "!")

Output

Enter your name: John
Hello, John!

In this example, the input() function is used to prompt the user to enter their name.

The entered name is then assigned to the variable name, and the print() function is used to display a greeting using the entered name.

Python Program to get input from the user

name = input("Enter your name: ")
age = int(input("Enter your age: "))

print("Your name is", name)
print("Your age is", age)

Output

Enter your name: Emma
Enter your age: 17
Your name is Emma
Your age is 17

In this program, we use the input() function to take input from the user.

The first input() statement prompts the user to enter their name.

The entered value is assigned to the name variable.

The second input() statement prompts the user to enter their age.

The entered value is converted to an integer using the int() function and assigned to the variable age.

We then use the print() function to display the values of name and age.

Was this helpful?
YesNo

Related Articles:

Recent Articles:

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x