Tell us what’s happening:
Hello!! I’ve been doing the first project but I’m stuck. I would like to know if my code is correct so far, and also an idea of how to do the last part of the assignment.
Thanks in advance!!!
Your code so far
def arithmetic_arranger(problems, b):
if len(problems) > 5:
return “”“Error: Too many problems.”""
elif b == False or b == None:
pass
for number in problems:
s = str(number)
if ("*" or "/") in s:
return "Error: Operator must be '+' or '-'."
elif (number.isalpha()) == True:
return "Error: Numbers must only contain digits."
else:
pass
for i, problem in enumerate(problems):
num1, op, num2 = problem.split()
if len(num1) > 4 or len(num2) > 4:
return "Error: Numbers cannot be more than four digits."
else:
pass
else:
for number in problems:
result = eval(number)
print (number, '----', result)
return arranged_problems #This is where I’m stuck. I don’t know how to make the columns and the indentation between them
print(‘First:’, test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “523 - 49”], True))
print(‘Second:’,test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “523 - 49”, “1 - 2”, “3 + 5”], False)) #too many operations, just up to 5
print(‘Third:’,test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “523 - 49”, “9 * 1”], True)) #only ‘+’ or ‘-’. NOT ‘*’ or ‘/’
print(‘Fourth:’, test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “abc”], True)) #only digits can appear
print(‘Fifth:’, test_1([“32 + 8”, “1 - 3801”, “9999 + 9999”, “85000 - 54000”], True)) #numbers should not have more than 4 units
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36
.
Challenge: Arithmetic Formatter
Link to the challenge: