Tell us what’s happening:
Describe your issue in detail here.
import re
def arithmetic_arranger(problems, display=False):
# Too many problems error
if len(problems) > 5:
raise Exception("Too many problems.")
# Operator error
for problem in problems:
Prob = re.split(" ", problem)
if '+' not in Prob or '-' not in Prob:
raise Exception("Operator must be '+' or '-'.")
# Digit error
for problem in problems:
Prob = re.split(" ", problem)
if prob[problem][0].isdigit() is False or prob[problem][-1].isdigit is False:
raise Exception("Numbers must only contain digits.")
# integer len error
if len(problems[problem][0]) > 4 or len(problems[problem][-1]) > 4:
raise Exception("Numbers cannot be more than four digits.")
blocks=[]
for problem in problems:
blocks.append(preprocess(problem,display))
if type(blocks[-1])==str:
raise blocks[-1]
arranged_problems=''
if display==True:
count=4
else:
count=3
for i in range(count):
for j in blocks:
arranged_problems+=j[i]+seperator
if j==blocks[-1]:
arranged_problems=arranged_problems[0:-4]
arranged_problems+='\n'
raise arranged_problems[0:-1]
print(arithmetic_arranger)
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36
Challenge: Arithmetic Formatter
Link to the challenge: