Write a program to enter two numbers and print the arithmeticoperations like +,-,*,**, /, // and % using function
Question
Write a program to enter two numbers and print the arithmeticoperations like +,-,*,**, /, // and % using function
Solution
Sure, here is a simple Python program that performs arithmetic operations on two numbers:
def arithmetic_operations(num1, num2):
print("Addition: ", num1 + num2)
print("Subtraction: ", num1 - num2)
print("Multiplication: ", num1 * num2)
print("Exponent: ", num1 ** num2)
print("Division: ", num1 / num2)
print("Floor Division: ", num1 // num2)
print("Modulus: ", num1 % num2)
# Test the function
arithmetic_operations(10, 2)
This program defines a function arithmetic_operations that takes two numbers as arguments and prints the result of various arithmetic operations on them. The function is then called with the numbers 10 and 2 as arguments.
Please replace the numbers 10 and 2 with the numbers you want to perform arithmetic operations on.
Similar Questions
Write a program that does basic arithmetic operations (addition, subtraction, multiplication,and division). The inputs to the program are two numbers (in double format) and theoperation required. Provide a function for each operation and the identifiers for addition,subtraction, multiplication, and division are ‘+’, ‘-‘, ‘*’, and ‘/’ respectively
Charlie, a novice programmer, is developing a simple calculator program to perform basic arithmetic operations. He needs your assistance in refining the program.Write a program that takes an operator ('+', '-', '*', or '/') and two operands as input. The program should then perform the corresponding operation and display the result. If the input is an invalid operator, the program should display an appropriate error message.Function Specifications:double add(double x, double y)double subtract(double x, double y)double multiply(double x, double y)double divide(double x, double y)Input format :The first line of input consists of a character c, representing the operator (+, -, *, /).The second line consists of two space-separated double values a and b, representing the operands.Output format :
.Write a C program that prompts a user for two integers and the appropriate operator(i.e. +,-,/,*) then uses switch case to determine the appropriate operation.
You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation.Evaluate the expression. Return an integer that represents the value of the expression.Note that:The valid operators are '+', '-', '*', and '/'.Each operand may be an integer or another expression.The division between two integers always truncates toward zero.There will not be any division by zero.The input represents a valid arithmetic expression in a reverse polish notation.The answer and all the intermediate calculations can be represented in a 32-bit integer. Example 1:Input: tokens = ["2","1","+","3","*"]Output: 9Explanation: ((2 + 1) * 3) = 9
Priya is fascinated by maths and wants to calculate the value for the given expression: ++a * ++b / a. The program takes these 2 values as input, calculates the expression, and displays the result.Can you help her by writing a program?Input format :The first line consists of a integer value a, representing the first value.The second line consists of a integer value b, representing the second valueOutput format :The output displays a result as integer.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.