Skip to content

Input Statement

Input Statement:
Input is the activity that accept data from the user into python program.

 

The input() function is used to accept data from the user.

🐍
filename.py
#Example
print("Enter any number:")
num=input()
print("num=",num)

The input() can also be used to display prompt message to the user

🐍
filename.py

#Example
num=input("Enter any number:")
print("num=",num)

The input() function can accept data in the form of ‘string’.

To work with numeric data, we can convert the data obtained by input() function using Type conversion functions

🐍
filename.py
#Example
name=input("Enter your name:")
print("Hello",name,"Welcome")

#Example
num=input("Enter any number:")
print("Your number is:",num)

#Example
fname=input("Enter first name:")
lname=input("Enter last name:")
name=fname+" "+lname
print("Hello",name,"Welcome")

#Example
num1=int(input("Enter first number:"))
num2=int(input("Enter second number:"))
num3=num1+num2
print("Sum is:",num3)

#Example
num=int(input("Enter any number:"))
print("Square of your number is:",num*num)

Practice Questions:
1. Write python program to create two variables len and bre, initialise the variables with desired values and display area of rectangle.
Hint: area=len*bre

2. Write the above program to accept user input.

3. Write python program to calculate and print simple interest for the desired principle, rate of interest and tenure.
Hint: si=(p*n*r)/100

4. Write the above program for user input

5. Write Python program to calculate and print average of 3 user entered numbers.
Hint: avg=(a+b+c)/3

6. Try other previous programs too as taking input from user