📜  Python 算术运算

📅  最后修改于: 2020-10-30 00:44:26             🧑  作者: Mango

Python做算术运算

算术运算由计算器执行,我们可以执行加,减,乘和除运算。这个例子展示了基本的算术运算,即

  • 加成
  • 减法
  • 乘法
  • 除法

请参阅以下示例:

# Store input numbers:
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')

# Add two numbers
sum = float(num1) + float(num2)
# Subtract two numbers
min = float(num1) - float(num2)
# Multiply two numbers
mul = float(num1) * float(num2)
#Divide two numbers
div = float(num1) / float(num2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

# Display the subtraction
print('The subtraction of {0} and {1} is {2}'.format(num1, num2, min))
# Display the multiplication
print('The multiplication of {0} and {1} is {2}'.format(num1, num2, mul))
# Display the division
print('The division of {0} and {1} is {2}'.format(num1, num2, div))

注意:此处输入数字为10和20。

输出: