Guidelines

How to Gather Information from Users

When creating a program, there are times when you need to gather information from the user. In such cases, the input() function comes into play.

The input function returns data entered by the user through the keyboard as a string (text data).


How is it used?

The input() function displays a message to the user and waits for the user's input.

Once the user presses the enter key, the input process ends, and the entered content is returned as a string.

Using the input() function
user_input = input("Please enter your name:") # Displays a message to the user and waits for the user's input print("Welcome", user_input) # Outputs "Welcome [user input]"

When is it typically used?

The input() function is used when you need to receive settings, information, or data necessary for the program from the user.

Example using the input function
name = input("Please enter your name: ") hobby = input("Please enter your hobby: ") print(name + "'s hobby is " + hobby + ".")

Precautions

The input function always returns the data received from the user as a string (text data).

If you need to receive a number, you must use the int() function to convert it to a number.

Receiving Numeric Input
user_input = input("Please enter a number: ") number = int(user_input) print(number)

Coding Practice

Try using Python's input function to gather information from users.

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result