Python 程序:将两个数字相乘

编写一个 Python 程序来相乘两个数字。此示例接受两个整数值并计算这两个数字的乘积。

num1 = int(input("Please Enter the First Number to Multiply  = "))
num2 = int(input("Please Enter the second Number to Multiply = "))

mul = num1 * num2
print('The Result of Multipling {0} and {1} = {2}'.format(num1, num2, mul))
Python Program to Multiply Two numbers

下面的程序将接受并相乘两个浮点数。

num1 = float(input("Please Enter the First  = "))
num2 = float(input("Please Enter the second = "))

mul = num1 * num2
print('The Result of Multipling {0} and {1} = {2}'.format(num1, num2, mul))
Please Enter the First  = 17.89
Please Enter the second = 28.56
The Result of Multipling 17.89 and 28.56 = 510.9384

程序 有助于使用函数相乘两个数字

# using Functions

def multiplyTwoNum(a, b):
    return a * b

num1 = int(input("Please Enter the Firs  = "))
num2 = int(input("Please Enter the second = "))

mul = multiplyTwoNum(num1, num2)
print('The Result of Multipling {0} and {1} = {2}'.format(num1, num2, mul))
Please Enter the First  = 12
Please Enter the second = 19
The Result of Multipling 12 and 19 = 228