Why the answer didn’t come, there’s an error in my codes, can you help me please
Your code so far
def arithmetic_arranger(problems, show_answers=False):
if len(problems) > 5:
return 'Error: Too many problems.'
a = ''
b = '\n'
c = '\n'
d = '\n'
for number in problems:
part = number.split()
#Abbreviation
n1 = part[0]
op = part[1]
n2 = part[2]
answer = 0
if op not in ["+", "-"]:
print('Error: Operator must be "+" or "-".')
if not n1.isdigit() or not n2.isdigit():
print('Error: Number must only contain digits.')
if len(n1) > 4 or len(n2) > 4:
print('Error: Numbers cannot be more than four digits')
if op == '+':
answer = int(n1) + int(n2)
elif op == '-':
answer = int(n1) - int(n2)
ans_len = len(str(answer))
dash_gap = (2 + max(len(n1), len(n2))) * '-'
n1_gap = (len(dash_gap) - len(n1)) * ' '
n2_gap = (len(dash_gap) - max(len(n1), len(n2)))
ans_gap = (len(dash_gap) - ans_len) * ' '
gap = 4 * ' '
a += f"{n1_gap}{n1}{gap}"
b += f"{op}{n2_gap}{n2}{gap}"
c += f"{dash_gap}{gap}"
d += f"{ans_gap}{answer}{gap}"
if show_answers:
result = a + b + c + d
else:
result = a + b + c
return result
arithmetic_arranger(["3801 - 2", "123 + 49"])
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project
Help, I begginer with this all, can you help me please, how to start to divide the code to 3 form, i tried but it return error, can you help me check what’s wrong with that
Your code so far
def arithmetic_arranger(problems, show_answers=False):
p1 = ''
p2 = '\n'
p3 = '\n\n'
ans = '\n\n\n'
part = problems.split()
n1 = part[0]
op = part[1]
n2 = part[2]
if len(n1) > 5:
return 'Error: Too many problems.'
if not op '+' or '-':
return "Error: Operator must be '+' or '-'."
if not n1.isdigit() or n2.isdigit():
return 'Error: Numbers must only contain digits.'
return problems
print(f'\n{arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])}')
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project
My Formatter Arithmathic
What wrong with this code, can anybody help me please, tysm for your assistance
Your code so far
def arithmetic_arranger(problems, show_answers=False):
#Line
p1 = ''
p2 = '\n'
p3 = '\n\n'
ans = '\n\n\n'
if len(problems) >= 5:
return 'Error: Too many problems.'
for num in problems:
#Divide
part = num.split()
n1 = part[0]
op = part[1]
n2 = part[2]
#Rules
if not op is '+' or op is '-':
return "Error: Operator must be '+' or '-'."
if not n1.isdigit() or not n2.isdigit():
return 'Error: Numbers must only contain digits.'
if len(n1) > 4 or len(n2) > 4:
return 'Error: Numbers cannot be more than four digits.'
if op is '+':
answer = int(n1) + int(n2)
else:
answer = int(n1) - int(n2)
#Dash
dash = '_'*(len(str(answer)) + 2)
#Line answer
l_ans = ' '*(len(dash) - len(str(answer)))
#Line 1
l1 = ' '*(len(dash) - len(n1))
#Line 2
l2 = ' '*(len(dash) - len(n1) - 1)
return problems
print(f'\n{arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])}')
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project
def arithmetic_arranger(problems, show_answers=False):
#Line
p1 = ''
p2 = '\n'
p3 = '\n'
ans = '\n'
if len(problems) > 5:
return 'Error: Too many problems.'
for num in problems:
#Divide
part = num.split()
n1 = part[0]
op = part[1]
n2 = part[2]
#Rules
if not op == '+' and not op == '-':
return "Error: Operator must be '+' or '-'."
if not n1.isdigit() or not n2.isdigit():
return 'Error: Numbers must only contain digits.'
if len(n1) > 4 or len(n2) > 4:
return 'Error: Numbers cannot be more than four digits.'
if op is '+':
answer = int(n1) + int(n2)
else:
answer = int(n1) - int(n2)
#Dash
dash = '_'*(len(str(answer)) + 2)
#Line
l_ans = ' '*(len(dash) - len(str(answer)))
#Line 1
l1 = ' '*(len(dash) - len(n1))
#Line 2
l2 = ' '*(len(dash) - len(n2) - 1)
#Gap
gap = ' '*4
#Answer
aof = ' '*(len(dash) - len(str(answer)))
p1 += f'{l1}{n1}{gap}'
p2 += f'{op}{l2}{n2}{gap}'
p3 += f'{dash}{gap}'
if show_answers == True:
ans += f'{aof}{answer}{gap}'
Final = p1 + p2 + p3 + ans
return Final
print(f'\n{arithmetic_arranger(["3801 - 2", "123 + 49"])}')
I’ve tried rpr(), and another solution to complete this Project, but the checklist didn’t correct it until now, can anyone help with with solution please
Your code so far
def arithmetic_arranger(problems, show_answers=False):
#Line
p1 = ''
p2 = '\n'
p3 = '\n'
ans = '\n'
if len(problems) > 5:
return 'Error: Too many problems.'
for num in problems:
#Divide
part = num.split()
n1 = part[0]
op = part[1]
n2 = part[2]
#Rules
if not op == '+' and not op == '-':
return "Error: Operator must be '+' or '-'."
if not n1.isdigit() or not n2.isdigit():
return 'Error: Numbers must only contain digits.'
if len(n1) > 4 or len(n2) > 4:
return 'Error: Numbers cannot be more than four digits.'
if op is '+':
answer = int(n1) + int(n2)
else:
answer = int(n1) - int(n2)
#Dash
dash = '_'*(len(str(answer)) + 2)
#Line
l_ans = ' '*(len(dash) - len(str(answer)))
#Line 1
l1 = ' '*(len(dash) - len(n1))
#Line 2
l2 = ' '*(len(dash) - len(n2) - 1)
#Gap
gap = ' '*4
#Answer
aof = ' '*(len(dash) - len(str(answer)))
p1 += f'{l1}{n1}{gap}'
p2 += f'{op}{l2}{n2}{gap}'
p3 += f'{dash}{gap}'
if show_answers == True:
ans += f'{aof}{answer}{gap}'
Final = p1 + p2 + p3 + ans
return Final
print((f'\n{arithmetic_arranger(["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"], True)}'))
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project