在了解了算术运算符之后编写实例进行验证,在basis目录下新建文件,命名为arithmetic.py,学习Python算术运算符的操作,在PyCharm中编写代码。
operand_a = 5
operand_b = 2
operand_c = 0
加法运算
operand_c = operand_a + operand_b
print("{} + {} = {}".format(operand_a, operand_b, operand_c))
减法运算
operand_c = operand_a - operand_b
print("{} - {} = {}".format(operand_a, operand_b, operand_c))
乘法运算
operand_c = operand_a operand_b
print("{} {} = {}".format(operand_a, operand_b, operand_c))
除法运算
operand_c = operand_a / operand_b
print("{} / {} = {}".format(operand_a, operand_b, operand_c))
取余运算
operand_c = operand_a % operand_b
print("{} % {} = {}".format(operand_a, operand_b, operand_c))
取整运算
operand_c = operand_a // operand_b
print("{} // {} = {}".format(operand_a, operand_b, operand_c))
乘幂运算
operand_c = operand_a operand_b
print("{} {} = {}".format(operand_a, operand_b, operand_c))