【发布时间】:2021-04-24 02:04:47
【问题描述】:
我正在尝试用 python 编写一个非常简单的计算器。问题是当我给出正数时它工作得很好但是当我输入负数时我没有得到任何答案......我不知道为什么。 如果有人可以帮助我,我将不胜感激:)。 这是我的代码:
print("Hi :) This is your simple calculator")
a = float(input("please enter the first number: "))
b = float(input("please enter the second number: "))
print(f"{a}+{b} is {round((a)+(b), 3)}, {a}-{b} is {round(a-(b), 3)}, {b}-{a} is {round(b-(a), 3)}, {a}*{b} is {round(a*(b), 3)}, {a}/{b} is {round(a/(b), 3 )}, {b}/{a} is {round(b/(a), 3)}, {a} to the power of {b} is {round((a)**(b), 3)}, {b}to the power of{a} is {round((b)**(a), 3)}, {b} root of {a} is {round((a)**(1/b), 3)}, {a} root of {b} is {round((b)**(1/a), 3)} ")
【问题讨论】:
-
当您输入负数时会得到什么?当你寻求帮助时,这一点很重要。请阅读How to Ask 和question checklist。欢迎使用 Stack Overflow!
标签: python calculator