Skip to main content

Write a python program to perform Arithmetic operations by Input function

Description

This Python code is a simple program that takes user input for two numbers, performs four basic arithmetic operations (addition, subtraction, multiplication, and division), and displays the results with appropriate messages for each operation.

Code

program2c.py
x=int(input("Enter number1"))
y=int(input("Enter number2"))
sum=x+y
print("the sum is=",sum)
sub=x-y
print("the sub is=",sub)
multi=x*y
print("the multi is=",multi)
division=x/y
print("the division is=",division)

Explanation of above code

  • The Python code is a simple program designed to perform four basic arithmetic operations on two user-input numbers: x and y.
  • It begins by utilizing the input function to collect user input for the values of x and y.
  • These input values are subsequently converted into integers using the int function, ensuring they can be used for mathematical calculations.
  • The program then proceeds to calculate and display the results of the four basic arithmetic operations: addition, subtraction, multiplication, and division.
  • For each operation, the code provides a message indicating the specific operation being executed and the corresponding result.
  • The user is presented with the sum, subtraction, multiplication, and division of the input numbers, offering a clear and interactive way to perform these calculations.

Learn more

Reference