当前分类:300例题>>正文

Python示例:两个数相乘

来源:互联网   更新时间:2023年6月16日  

Python 示例

写一个 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示例。

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

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

Python示例使用函数将两个数字相乘

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

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

mul = multiplyTwoNum(num1, num2)
print('The Result of Multipling {0} and {1} = {2}'.format(num1, num2, mul))
Please Enter the First Number to Multiply  = 12
Please Enter the second Number to Multiply = 19
The Result of Multipling 12 and 19 = 228
本文固定链接:https://6yhj.com/leku-p-4255.html  版权所有,转载请保留本地址!
[猜你喜欢]

标签: 智能AI