您的位置:

Python 程序:使用函数执行算术运算

写一个 Python 程序,用函数做算术计算。在这个 python 示例中,我们为算术计算定义了几个独立的函数,如加法、减法、除法、乘法、模数和指数。

def addition(num1, num2):
    return num1 + num2

def subtraction(num1, num2):
    return num1 - num2

def multiplication(num1, num2):
    return num1 * num2

def division(num1, num2):
    return num1 / num2

def floordivision(num1, num2):
    return num1 // num2

def modulus(num1, num2):
    return num1 % num2

def exponent(num1, num2):
    return num1 ** num2

num1 = int(input("Enter the First Value  = "))
num2 = int(input("Enter the Second Value = "))

print("The Addition       = {0}".format(addition(num1, num2)))
print("The Subtraction    = {0}".format(subtraction(num1, num2)))
print("The Multiplication = {0}".format(multiplication(num1, num2)))
print("The Division       = {0}".format(division(num1, num2)))
print("The Floor Division = {0}".format(floordivision(num1, num2)))
print("The Modulus        = {0}".format(modulus(num1, num2)))
print("The Exponent       = {0}".format(exponent(num1, num2)))