Chapter No -7 Input Function

 Input Function




The input function is an essential feature in Python that allows users to take input. This is particularly useful when you want to create interactive programs that allow users to provide data during execution. 

How the input function works:

The input function waits for the user to type something and then press enter. It reads the input as a string and returns it

Example:

# Prompting the user for their name

name = input("Enter your name:")

# Displaying the user's input

print("Hello, "+ name + "!")

Exercise

# Input Function in Python.

# # # The input() function is used to take input from the user.
# # # The input() function returns a string value.

a = input()
print(int(a)+(int(a))) # int is being used to convert string to integer.

Enter Your Value - 1

1+1 = 2

# # The Input function always reads the input value as a string.

name = input("Enter your name: ") # string
print(f"Welcome {name} to the Python tutorial series")

Enter Your Name - Madhav (In command prompt in vs code)

Output - Welcome Madhav to the Python tutorial series

age = input("Enter your age:") # string
print(f"Ohh, you are just {age} years old")

Enter Your Age - 25 (In command prompt in vs code)

Output - Ohh, you are just 25 years old

print(f"So, next year, you will be {int(age)+1}! years old")

Enter Your Age - 26 Output - So next year, you will be 26 years old

Post a Comment

Previous Next

نموذج الاتصال