Programmer Coding

Input() Function in Python

Input() in Python

The function concept in Python is a powerful tool to interact with the user and retrieve information from the keyboard while performing tasks. Whether you’re creating a simple script application or complex software, the input() function allows you to collect user input and make your program interactive, conversational, and powerful. In this article, we will examine Python input functions in detail. We will discuss how to use it to take user input, store the input as a variable, and perform various tasks based on that input. Additionally, we’ll cover best practices, pitfalls, and security considerations when using input() to ensure your Python programs are client-friendly and powerful.

Input Function in Python

Input functions are built-in functions in Python that allow developers to read user data. The input function in Python reads input as a string that can be converted to other data types such as numbers, floats, or Boolean values.

Syntax of Input Function in Python

The syntax of the input characteristic in python is straightforward. It takes a unmarried argument, that’s the message to be displayed to the consumer.

Syntax

input([prompt])

Parameters of Input Function in Python

it’s going to take only a unmarried argument that’s optional.

*prompt: it is a string that is written with recognize to conventional output with out going into a new line.

Return Type of Input Function in Python

The input() method reads a line from the input (often from the user), removes the terminating newline to turn the line into a string, and then returns the string.

An EOFError exception is raised if EOF is read

Examples  of Input Function in Python

# User Input
name = input("Enter Your Name : ")
# User Input
roll = int(input("Enter Your Roll No : "))
# User Input
age = int(input("Enter Your Age : "))
# User Input
marks = int(input("Enter Your Marks : "))
print("<><><><><><><><><><><><><><><><><><><><><><")
# Final Print
print("Your Name : ",name)
print("Your Roll No : ",roll)
print("Your Age : ",age)
print("Your Marks : ",marks)

Output

Enter Your Name : Ramkrishna kumar Mandal

Enter Your Roll No : 85

Enter Your Age : 23

Enter Your Marks : 445

<><><><><><><><><><><><><><><><><><><><><><

Your Name :  Ramkrishna kumar Mandal

Your Roll No :  85

Your Age :  23

Your Marks :  445

 

Example User Input Addition Of Two Number

x = int(input("Enter 1st Number : "))
y = int(input("Enter 2nd Number : "))
z = x + y
print("Addition Of Two Number = ",z)

Output

Enter 1st Number : 85

Enter 2nd Number : 65

Addition Of Two Number =  150

Example User Input Subtraction Of Two Number

x = int(input("Enter 1st Number : "))
y = int(input("Enter 2nd Number : "))
z = x - y
print("Subtraction Of Two Number = ",z)

Output

Enter 1st Number : 78

Enter 2nd Number : 41

Subtraction Of Two Number =  37

Example User Input Multiplication Of Two Number

x = int(input("Enter 1st Number : "))
y = int(input("Enter 2nd Number : "))
z = x * y
print("Multiplication Of Two Number = ",z)

Output

Enter 1st Number : 8

Enter 2nd Number : 7

Multiplication Of Two Number =  56

Example User Input Division Of Two Number

x = int(input("Enter 1st Number : "))
y = int(input("Enter 2nd Number : "))
z = x / y
print("Division Of Two Number = ",z)

Output

Enter 1st Number : 5

Enter 2nd Number : 2

Division Of Two Number =  2.5

Example User Input Floor Division Of Two Number

x = int(input("Enter 1st Number : "))
y = int(input("Enter 2nd Number : "))
z = x // y
print("Division Of Two Number = ",z)

Output

Enter 1st Number : 5

Enter 2nd Number : 2

Division Of Two Number =  2

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top