Tell us what’s happening:
I’d love some insight into why i can’t get the 4th problem to work in my code please!
Your code so far
def arithmetic_arranger(problems, show_answers=False):
#1st problem (length of problems)
if len(problems) > 5:
return 'Error: Too many problems.'
#2nd problem (only + and - operators accepted)
#Need to split the problem first in parts
for problem in problems:
individual_problems = problem.split()
#Specify the operators
operator = individual_problems[1]
if operator != '+' and '-':
return "Error: Operator must be '+' or '-'."
#3rd problem (operands should only contain digits)
operands = individual_problems[0] and individual_problems[2]
if operands is not operands.isdigit():
return 'Error: Numbers must only contain digits.'
#4th problem (operands can only be max 4 digits)
first_operand = individual_problems[0]
second_operand = individual_problems[2]
if len(first_operand) > 4 or len(second_operand) > 4:
return 'Error: Numbers cannot be more than four digits.'
print(f'\n{arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])}')
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Challenge Information:
Build an Arithmetic Formatter Project - Build an Arithmetic Formatter Project