Tell us what’s happening:
Please help me, I didn’t find my false. What do I have to do? Where is my false?
As you see my code, I wrote everything, and I tried, everything is running ohne problem. But system said me 1,2,3,4,9 and 10 is false.
Your code so far
def arithmetic_arranger(digits, show_results=False):
# Making arrangement
first_line = []
second_line = []
dashes = []
results = []
if len(digits) > 5:
return 'Error: Too many problems.'
for digit in digits:
# Split digits
parts = digit.split()
num1 = parts[0]
operator = parts[1]
num2 = parts[2]
# Valid input situations
if operator not in ['+', '-']:
return "Error: Operator must be '+' or '-'."
if not (num1.isdigit() and num2.isdigit()):
return 'Error: Numbers must only contain digits.'
if len(num1) > 4 or len(num2) > 4:
return 'Error: Numbers cannot be more than four digits.'
# Deciding width
width = max(len(num1), len(num2)) + 2
# Shaping digits in a format
first_line.append(num1.rjust(width))
second_line.append(operator + ' ' + num2.rjust(width - 2))
dashes.append('-' * width)
# Result display
if show_results:
if operator == '+':
result = str(int(num1) + int(num2))
else:
result = str(int(num1) - int(num2))
results.append(result.rjust(width))
# Combine the lines into a single output
arranged_digits ='\n' + ' '.join(first_line) +'\n' +' '.join(second_line) + '\n' +' '.join(dashes)
if show_results:
arranged_digits +='\n' +' '.join(results)
return arranged_digits
# Test the function
# problem1 =
print(arithmetic_arranger(["3801 - 2", "123 + 49"]))
# problem2 =
print(arithmetic_arranger(["1 + 2", "1 - 9380"]))
# problem3 = ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]
print(arithmetic_arranger(["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]))
# problem4 = ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]
print(arithmetic_arranger(["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]))
# problem9 =
print(arithmetic_arranger(["3 + 855", "988 + 40"],True))
# problem10 = ["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"]
print(arithmetic_arranger(["32 - 698", "1 - 3801", "45 + 43", "123 + 49", "988 + 40"],True))
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project