Introduction
We use input() to get information from the person using the program. It helps the program to ask questions and get answers.
Jump into concepts and practice - no test required
We use input() to get information from the person using the program. It helps the program to ask questions and get answers.
variable = input(prompt)prompt is the message shown to the user to explain what to type.
The input() function always returns text (a string).
name.name = input("Enter your name: ")
age = input("Enter your age: ")
color = input()This program asks the user for their name and age, then says hello using the information.
name = input("What is your name? ") age = input("How old are you? ") print(f"Hello, {name}! You are {age} years old.")
Remember, input() always gives text. To use numbers, convert with int() or float().
If you forget to add a prompt, the program will wait silently for input.
input() lets your program talk to the user and get answers.
Always use a prompt to help the user know what to type.
Input is text, so convert it if you need numbers.
input() function do in Python?input()input() function waits for the user to type something and press Enter.input() returnsinput() returns text [OK]input()?input() with promptinput('prompt').25 when asked?
age = input('Enter your age: ')
print(age + 5)age will be the string '25', not the number 25.age + 5 attempts to add a string and an integer. In Python, this causes a TypeError, but if the code was print(age + '5'), it would concatenate to '255'. Since the code is print(age + 5), it raises a TypeError.number = input('Enter a number: ')
result = number * 2
print(result)numberinput() function returns a string, so number is text.number * 2 does for stringsint().