So, I've been working at this for hours and hours, this is a homework assignment and I just can't figure out why the code doesn't execute completely. I provided all the code to see if there was something I missed outside of the 'assign2' function. However, I know the issue is down there and want to figure out what's wrong.
I'm essentially trying to take the number that is generated last and turn it back into letters representative of Napier arithmetic (i.e. a = 0, b = 1, c = 2...z = 25) and putting them together in a list that I can print in the main function. Everything else works except for this last part and I'm trying to figure out why.
def main():
again = "y"
while again == "y" or again == "Y":
var = checkalpha()
num = assign(var)
print("The first number is: {}".format(num))
var2 = checkalpha()
num2 = assign(var2)
print("The second number is: {}".format(num2))
arithmetic = getsign()
value = equation(num, num2, arithmetic)
newvar = assign2(value)
print("The result is {} or {}".format(value, newvar))
again = input("Would you like to repeat the program? Enter y for yes, n for no: ")
def checkalpha():
num = input("Enter Napier number: ")
while not num.isalpha():
print("Something is wrong. Try again.")
num = input("Enter Napier number: ")
return num
def assign(char):
value = 0
for ch in char:
value += 2 ** (ord(ch) - ord("a"))
return value
def getsign():
operand = input("Enter the desired arithmetic operation: ")
while operand not in "+-*/":
operand = input("Something is wrong. Try again. ")
return operand
def equation(num, num2, arithmetic):
if arithmetic == "+":
answer = num + num2
elif arithmetic == "-":
answer = num - num2
elif arithmetic == "*":
answer = num * num2
elif arithmetic == "/":
answer = num / num2
else:
input("Something is wrong. Try again. ")
return answer
def assign2(n):
new = []
while n != 0:
value = n%2
x = n//2
ch = chr(value + ord("a"))
new.append(ch)
n = x
return new
main()