python 3.x - adding functions to self made calculator -
ok i'm trying make working napier numeral calculator. have gone through of steps need make work. need 2 more steps function , converting napier numbers. i'm stuck on getting functions work. seems skip step. can tell should work , not skipped. tell me if missed step in process of making function.
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 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()
this result can see gets napier numbers , stops
enter napier number: asdf 262185 enter napier number: adsf 262185 262185 try another[y/n]
your line operator = getoperator
should operator = getoperator()
Comments
Post a Comment