【发布时间】:2016-04-19 23:57:44
【问题描述】:
好的,所以我正在尝试制作一个可以使用的内皮数字计算器。我已经完成了使它工作所需的大部分步骤。我还需要 2 个步骤的功能并将其转换回napier 数字。目前我一直坚持让这些功能正常工作。它似乎只是跳过了这一步。据我所知,它应该可以工作而不是被跳过。谁能告诉我我是否错过了制作功能的过程中的一步。
def main():
response = 'y'
while response == 'y' or response == 'Y':
nap1 = getNapier()
num1 = napToInt(nap1)
print(num1)
nap2 = getNapier()
num2 = napToInt(nap2)
print(num1, num2)
operator = getOperator
result = doMath(num1, num2, operator)
response = input("Try another[y/n]")
def doMath(num1, num2, operator):
if operator == "+":
answer = num1 + num2
elif operator == "-":
answer = num1 - num2
elif operator == "*":
answer = num1 * num2
else:
if operator == "/":
answer = num1 / num2
return doMath
def getOperator():
op = input("Enter operator: ")
while op not in "+-*/":
op = input("Error!!!! Enter operator: ")
return op
def napToInt(n):
result = 0
for ch in n:
result += 2 ** (ord(ch) - ord('a'))
return result
def getNapier():
nap = input("Enter Napier number: ")
while not nap.isalpha():
nap = input("Error!!! Enter Napier number: ")
return nap
main()
这是我得到的结果,你可以看到它得到了小数点,然后就停止了
Enter Napier number: asdf
262185
Enter Napier number: adsf
262185 262185
Try another[y/n]
【问题讨论】:
标签: function python-3.x math calculator