Saturday, 4 December 2021

Arithmetic Operations in Python

Like other languages python is also rich set of  operators. The following example demonstrate you how to use various arithmetic operations available in python. 


We can also type conversion while using the operands in the operations like other languages.

# Store input numbers:  
    a = input('Enter first number: ')  
    b = input('Enter second number: ')  
      
    # Add two numbers  
    sum = float(a) + float(b)  
    # Subtract two numbers  
    min = float(a) - float(b)  
    # Multiply two numbers  
    mul = float(a) * float(b)  
    #Divide two numbers  
    div = float(a) / float(b)  
    # Display the sum  
    print(sum)  
      
    # Display the subtraction  
    print(min)  
    # Display the multiplication  
    print(mul)  
    # Display the division  
    print(div)  

In the above example, the integer types are converted to float to display all results in float purpose .

The result of above program is 

Enter first number: 10
Enter second number: 20
30.0
-10.0
200.0
0.5

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

Find Us On Facebook

Computer Basics

More

C Programming

More

Java Tutorial

More

Data Structures

More

MS Office

More

Database Management

More
Top