Get error
def arithmetic_arranger(problems,need_answer=False):
first_line=’’
second_line=’’
third_line=’’
final_line=’’
if len(problems)>5:
return ‘Error: Too many problems.’
for prob in problems:
new_prob=prob.split()
first,op,second=new_prob[0],new_prob[1],new_prob[2]
if not((op=='+') or (op=='_')):
return "Error: Operator must be '+' or '-'."
elif len(first)>4 or len(second) >4:
return 'Error: Numbers cannot be more than four digits.'
elif not(first.isdigit() or second.isdigit()):
return 'Error: Numbers must only contain digits.'
if op=='+':
answer=int(first)+int(second)
elif op=='-':
answer=int(first)-int(second)
width=max(len(first),len(second))+2
separation=' '
first_option=str(first.rjust(width))
second_option=op+str(second).rjust(width-1)
third_option=str('-'*width)
fourth_option =str(answer).rjust(width)
if len(problems)>0:
first_line+=first_option+separation
second_line+=second_option+separation
third_line+=third_option+separation
final_line+=fourth_option+separation
if need_answer==True:
arranged_problems=first_line+'\n'+second_line+'\n'+third_line+'\n'+final_line
else:
arranged_problems=first_line+'\n'+second_line+'\n'+third_line
return print(arranged_problems)
def arithmetic_arranger(problems,need_answer=False):
first_line=''
second_line=''
third_line=''
final_line=''
if len(problems)>5:
return 'Error: Too many problems.'
for prob in problems:
new_prob=prob.split()
first,op,second=new_prob[0],new_prob[1],new_prob[2]
if not((op=='+') or (op=='_')):
return "Error: Operator must be '+' or '-'."
elif len(first)>4 or len(second) >4:
return 'Error: Numbers cannot be more than four digits.'
elif not(first.isdigit() or second.isdigit()):
return 'Error: Numbers must only contain digits.'
if op=='+':
answer=int(first)+int(second)
elif op=='-':
answer=int(first)-int(second)
width=max(len(first),len(second))+2
separation=' '
first_option=str(first.rjust(width))
second_option=op+str(second).rjust(width-1)
third_option=str('-'*width)
fourth_option =str(answer).rjust(width)
if len(problems)>0:
first_line+=first_option+separation
second_line+=second_option+separation
third_line+=third_option+separation
final_line+=fourth_option+separation
if need_answer==True:
arranged_problems=first_line+'\n'+second_line+'\n'+third_line+'\n'+final_line
else:
arranged_problems=first_line+'\n'+second_line+'\n'+third_line
return print(arranged_problems)