好的,所以我试图制作一个工作的纳米数字计算器。我已经完成了使其工作所需的大部分步骤。我还需要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]
答案 0 :(得分:1)
您的第operator = getOperator
行应为operator = getOperator()