Tell us what’s happening:
Hello! I’m new to python and this is my first technical challenge for me. I’ve gotten a decent start on the code but I’m stuck on where to actually format the problems. I’ve thought about indexing into the string to get the values needed for the formatter but I’m having trouble with figuring it out. Also if there’s any other changes that should be done with my code please let me know. Thank you!
Your code so far
import string
def arithmetic_arranger(problems):
for problem in problems:
fir_int = problem[]
op = problem[]
sec_int = problem[]
# Catches if there are more than 5 problems
if int(len(problems)) > 5:
print("Error: Too many problems")
quit(1)
# Catches incorrect operators put in function
elif '*' in problem:
print("Error: Operator must be '+' or '-'.")
quit(1)
# Catches if there are characters other than digits in the list
elif problem in string.ascii_lowercase:
print("Error: Numbers must only contain digits.")
quit(1)
# Catches the digits only being a max of four digits
elif len(problem) > 11:
print("Error: Numbers cannot be more than four digits.")
quit(1)
else:
# print out the numbers in correct format
# print(fir_int)
# print(op + sec_int)
# work on implementing solution
Link above should take you there. I did it on Pycharm initially. Do you mind clarifying what you mean by returning the strings? and is there any tips you can give to put me on the right track? I’ve tried to come up with solutions in my head but I can’t seem to get a grasp on it. Thank you for your help!
Oh thank you for clarifying the return statements but I’m not quite sure what you meant with the hint you gave me. can you clarify one more time? Sorry to be a bother but I really want to understand.
Are you saying for it to be formatted like that I need other variables and/or I need to use \n in the concatenation of the strings for it to be formatted correctly?