Tell us what’s happening:
So… I think I have finished my code beautifully. I check every condition and it apply to the rule. Is this consider a pass, and if yes how do i get a certificate. Or is it about the return thing, since i just group up the list? Please help!!!
Your code so far
def check_problems(problems):
problem_count=0
for char in problems:
problem_count+=1
if problem_count>5:
raise ValueError('Error: Too many problems.')
else:
pass
if char.find("+")==-1:
if char.find("-")==-1:
raise ValueError("Error: Operator must be '+' or '-'.")
else:
pass
return problems
def arithmetic_arranger(problems, show_answers=False):
check_problems(problems)
sticky=[]
box=[]
for char in problems:
sticky.append(char.replace(" ",""))
#print(sticky)
line1=[]
line2=[]
line_dash=[]
line_answer=[]
for seperating in sticky:
#check symbol
if seperating.find("+")!=-1:
symbol="+"
else:
symbol="-"
#creating front number
symlo=seperating.find(symbol)
front= seperating[0:symlo]
#print(front)
number="1234567890"
for i in front:
if number.find(i)==-1:
raise ValueError ('Error: Numbers must only contain digits.')
if int(front)//10000>0:
raise ValueError('Error: Numbers cannot be more than four digits.')
front_digit=symlo
#creating back number
back= seperating[symlo+1:]
#print(back)
for i in back:
if number.find(i)==-1:
raise ValueError ('Error: Numbers must only contain digits.')
if int(back)//10000>0:
raise ValueError('Error: Numbers cannot be more than four digits.')
back_digit=len(seperating)-symlo-1
max_digit=max(front_digit,back_digit)
indent1=max_digit+2-front_digit
indent2=max_digit+1-back_digit
answer=str(int(front)+int(back))
indenta=max_digit+2-len(answer)
#print(indenta)
dash=""
indent_up=""
indent_down=""
indent_answer=""
for _ in range(max_digit+2):
dash+="-"
for _ in range(indent1):
indent_up+=" "
for _ in range(indent2):
indent_down+=" "
for _ in range(indenta):
indent_answer+=" "
line1.append(indent_up+front)
line2.append(symbol+indent_down+back)
line_dash.append(dash)
line_answer.append(indent_answer+answer)
all_line1=" ".join(line1)
all_line2=" ".join(line2)
all_dash=" ".join(line_dash)
all_answer=" ".join(line_answer)
print(f'\n{all_line1}\n{all_line2}\n{all_dash}')
if show_answers==True:
print(f'{all_answer}')
return
arithmetic_arranger(["3801 - 2", "123 + 49"])
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.3 Safari/605.1.15
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project