Skip to content

Commit

Permalink
Update 1001S02E03_calculator.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Bear127 committed Sep 2, 2019
1 parent 034b8a9 commit c867408
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions exercises/1901010072/1001S02E03_calculator.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
def add(a: object, b: object) -> object:
"""
:rtype: object
"""
return a + b

a=3
b=4
print(add(a,b))

def subtract(c, d):
return c - d


def multiply(e, f):
return e * f


def divide(g, h):
return g / h
# 实现一个简单的计算器
# 1 接收用户输入的第一个数字(字符串类型),并转化为整数类型int
first_num = input('请输入第一个数字:')
first_num = int(first_num)
# 2 接收用户输入的运算符
symbol = input('请输入运算符(+,-,*,/):')
# 3 接收用户输入的第二个数字(字符串类型),并转化为整数类型int
sec_num = input('请输入第二个数字:')
sec_num = int(sec_num)
# 4 代码进行判断,计算
if symbol == '+':
result = first_num + sec_num
print(f'{first_num}{symbol}{sec_num}={result}')

elif symbol == '-':
result = first_num - sec_num
print(f'{first_num}{symbol}{sec_num}={result}')

elif symbol == '*':
result = first_num * sec_num
print(f'{first_num}{symbol}{sec_num}={result}')

elif symbol == '/':
if sec_num == 0
result = '除数不能为0'
print(result)
else:
result = first_num / sec_num
print(f'{first_num}{symbol}{sec_num}={result}')

else:
result = '输入错误'
print(result)

# 5 显示计算的结果,以及完整的等式
# 格式化输出 format
# print(result)
print(f'{first_num}{symbol}{sec_num}={result}')

1 comment on commit c867408

@Bear127
Copy link
Contributor Author

@Bear127 Bear127 commented on c867408 Sep 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自学训练营学习2群Day03

@liujiayi0042

Please sign in to comment.