Tell us what’s happening:
one last failure, i dont understand what is required, please can anyone help?
Your code so far
def arithmetic_arranger(problems, sn = True):
topLine = ''
buttomLine = ''
underLine = ''
answer = ''
total = 0
arranged_problems = ''
operand = ''
if len(problems) > 5:
return 'Error: Too many problems.'
for problem in problems:
spliting = problem.split()
numerator = spliting[0]
operand = spliting[1]
denumerator = spliting[2]
if len(numerator) > 4:
return "Error: Numbers cannot be more than four digits."
if len(denumerator) > 4:
return "Error: Numbers cannot be more than four digits."
if not numerator.isnumeric() or not denumerator.isnumeric():
return "Error: Numbers must only contain digits."
if operand == '+' or operand == '-':
if operand == '+':
total = str(int(numerator) + int(denumerator))
elif operand == '-':
total = str(int(numerator) - int(denumerator))
else:
return "Error: Operator must be '+' or '-'."
length = max(len(numerator), len(denumerator)) + 2
if problem != problems[-1]:
topLine += numerator.rjust(length) + ' '
buttomLine += operand + denumerator.rjust(length - 1) + ' '
underLine += "-" * length + ' '
answer += str(total).rjust(length) + ' '
else:
topLine += numerator.rjust(length)
buttomLine += operand + denumerator.rjust(length - 1)
underLine += "-" * length
answer += str(total).rjust(length)
if sn:
arranged_problems = F"{topLine}\n{buttomLine}\n{underLine}\n{answer}"
else:
arranged_problems = F"{topLine}\n{buttomLine}\n{underLine}"
return arranged_problems
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
.
Challenge: Arithmetic Formatter
Link to the challenge: