Python实现计算器功能 V1.0

# -*- coding: utf-8 -*-
# 选择运算规则
print('please choose the operate rules:')
print('1:addition           2:Subtraction  '
      '3:multiplication     4:division')
num = int(input())
print('please input a number:')
a = int(input())
print('please input another number:')
b = int(input())

# 加法
if num == 1:
    print('%d' '+' '%d' '=' '%d ' % (a, b, a + b))

# 减法
elif num == 2:
    print('%d' '-' '%d' '=' '%d ' % (a, b, a - b))

# 乘法
elif num == 3:
    print('%d' '*' '%d' '=' '%d ' % (a, b, a * b))

# 除法
elif num == 4:
    if b == 0:
        print('Error!!! 0 could not be divisor')
    else:
        print('%d' '/' '%d' '=' '%d ' % (a, b, a / b))

else:
    print('Error choice! Try again.')

你可能感兴趣的:(python)