Hi, I believe that all my code is running correctly and every single test that I’ve run is fully correct and displaying as it should be but for some reason it is not passing me
Can someone tell me if there is anything wrong with my code?
Your code so far
def arithmetic_arranger(problems, show_answers=False):
count_multiply = 0
count_division = 0
count_total = 0
operator_check_length = float(-2)*len(problems)
digits_check_list = []
list_of_more_than_4_digits = []
list_of_less_than_4_digits = []
number_of_dashes_list = []
row1 = []
row2 = []
row3 = []
row4 = []
if len(problems) > 5:
print('Error: Too many problems.')
else:
for individual_problem in problems:
multiply_check = individual_problem.find('*')
division_check = individual_problem.find('/')
count_multiply += multiply_check
count_division += division_check
count_total = count_multiply + count_division
if count_total != operator_check_length:
print("Error: Operator must be '+' or '-'.")
else:
for individual_problem in problems:
individual_problem_space_removed = individual_problem.replace(' ', '0')
if individual_problem_space_removed.find('+') == -1:
individual_problem_digits_check = individual_problem_space_removed.replace('-','0')
digits_check_list.append(individual_problem_digits_check)
elif individual_problem_space_removed.find('-') == -1:
individual_problem_digits_check = individual_problem_space_removed.replace('+','0')
digits_check_list.append(individual_problem_digits_check)
converted_to_digits = ''.join(digits_check_list)
if converted_to_digits.isdigit():
for problem in problems:
split_list = problem.split()
for individual_components in split_list:
if individual_components == '+' or individual_components == '-':
pass
elif individual_components.isdigit:
if int(individual_components) <10000:
list_of_less_than_4_digits.append(individual_components)
else:
list_of_more_than_4_digits.append(individual_components)
if list_of_more_than_4_digits == []:
for problem in problems:
sub_everything = problem.split()
row1.append(' '*(max(len(sub_everything[0]),len(sub_everything[2]))+2-len(sub_everything[0]))+sub_everything[0]+' '*4)
for problem in problems:
sub_everything2 = problem.split()
row2.append(sub_everything2[1]+' '*((max(len(sub_everything2[0]),len(sub_everything2[2]))+1)-len(sub_everything2[2]))+sub_everything2[2]+' '*4)
for problem in problems:
sub_everything3 = problem.split()
row3.append('-'*(max(len(sub_everything3[0]),len(sub_everything3[2]))+2)+' '*4)
for problem in problems:
sub_everything4 = problem.split()
row4.append(' '*(max(len(sub_everything4[0]),len(sub_everything4[2]))+2-int(len(str(int(sub_everything4[0])+(int(sub_everything4[1]+'1')*int(sub_everything4[2]))))))+str(int(sub_everything4[0])+(int(sub_everything4[1]+'1')*int(sub_everything4[2])))+' '*4)
print(''.join(row1).rstrip())
print(''.join(row2).rstrip())
print(''.join(row3).rstrip())
if show_answers == True:
print(''.join(row4))
else:
print('Error: Numbers cannot be more than four digits.')
else:
print('Error: Numbers must only contain digits.')
return problems
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project
Please update the message to include your code. The code was too long to be automatically inserted by the help button.
When you enter a code, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
if you open the browser console you should see a more detailed output of the tests
Click here for more infos on how to read an AssertionError
The assertion error and diff gives you a lot of information to track down a problem. For example:
AssertionError: 'Year' != 'Years'
- Year
+ Years
? +
Your output comes first, and the output that the test expects is second.
AssertionError: ‘Year’ != ‘Years’
Your output: Year does not equal what’s expected: Years
This is called a diff, and it shows you the differences between two files or blocks of code:
- Year
+ Years
? +
- Dash indicates the incorrect output + Plus shows what it should be ? The Question mark line indicates the place of the character that’s different between the two lines. Here a + is placed under the missing s .
Here’s another example:
E AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E assert ' 3801 123 \n - 2 + 49 \n------ ----- \n' == ' 3801 123\n- 2 + 49\n------ -----'
E - 3801 123
E + 3801 123
E ? ++++
E - - 2 + 49
E + - 2 + 49
E - ------ -----
E + ------ -----
E ? +++++
The first line is long, and it helps to view it as 2 lines in fixed width characters, so you can compare it character by character:
Again, your output is first and the expected output is second. Here it’s easy to see extra spaces or \n characters.
E - 3801 123
E + 3801 123
E ? ++++
Here the ? line indicates 4 extra spaces at the end of a line using four + symbols. Spaces are a little difficult to see this way, so it’s useful to use both formats together.