 # Introduction

“Consistency is more important than perfection”

In this article, we will be discussing how to interact with our users and how to do basic operations with a few basic operators.

# Input function

The input function allows the user to input any value and we can save it with the help of a variable for future use.

## Syntax

``variable=input(prompt)``

Here, the prompt is totally optional, if we write something inside the prompt it will be displayed before getting the input, if we leave it empty no message will be displayed but just waiting for the input.

Always try to write the correct prompt for making a user-friendly program.

## Example

```name=input("Enter your name: ")
print("Hello", name)
```

## Output

``````Enter your name: xyz
Hello xyz``````

## Explanation

In line 1 we are getting the input from the user and saving it inside a variable called name.

In line 2, we are greeting the user with the help of the variable where we have saved the name.

By default, all the input given by the user is going to be a string data type. If you want to convert the string to any other data type then we need to write the input function between the data type name.

For example,

```num1=int(input("Enter a number:"))#---> int is used to convert string to integer.
num2=float(input("Enter a float number"))#---> float is used to convert string to float.
```

# Operators

In python, we are having 7 different categories of operators. In this article, we will be seeing only the basic 4 categories of operators.

• Arithmetic operator
• Comparison operator
• Logical operator
• Assignment operator

The other 3 which we are going to cover in the later part of the tutorial are,

• Identity operator
• Membership operator
• Bitwise operator

Now, let us see all the operators in detail.

## Arithmetic operator

Arithmetic operators are generally used to perform mathematical operations between numbers (int and float)

## Comparison operator

Comparison operators compare two values and return the answer in boolean form (True or False).

## Logical operator

Logical operators are used to combining conditional statements and returns True or False.

## Assignment operator

Assignment operators are used to assigning values to variables.

# Practice yourself

• Get two numbers from the user and print their addition, subtraction, multiplication, and division.
• Get English, maths, science, social, and computer marks from the user and find his average marks.
• Explore all the operators with different kinds of input and explore the answers.
• Perform arithmetic operations on complex numbers.
• Combine two different data types with different operators and explore the output.

# Conclusion

Thus, now you must be having a clear idea regarding input function and different basic operators. As the quote goes, “We all learn from our mistakes”. Try to make mistakes and explore the different results and share them in the comments, which can help others to learn from your mistakes.

### 1 thought on “Input Function and Basic Operators in Python”

1. Pingback: Rock Paper Scissor Game in python - 