however it keeps saying the same thing
Unfortunately, I can’t really help.
-
I have to sleep
-
I don’t really understand what error you are trying to describe
It would be much easier if you include a link to your repl
Tell us what’s happening:
Describe your issue in detail here.
import re
def arithmetic_arranger(problems, solve = False):
if (len(problems) > 5):
return "Error: Too many problems."
first = ""
second = ""
lines = ""
sumx = ""
string = ""
for problem in problem :
if(re.search("[^\s0-9.+-]",problem)):
if(re.search("[/]", problem) or re.search("(*)", problem)):
return "Error: operator must be '+' or '-'."
return "Error: Numbers must only contain digits."
firstNumber = problem.split(" ")[0]
operator = problem.split(" ")[1]
secondNumber = problem.split(" ")[2]
if(len(firstNumber) >= 5 or len (secondNumber) >= 5 ):
return "Error: Numbers cannot be more than four digits."
sum = ""
if (operator == "+"):
sum = str(int(firstNumber) + int(secondNumber))
elif(operator == "-"):
sum = str(int(firstNumber) - int(secondNumber))
length = max(len(firstNumber), len(secondNumber)) + 2
top = str(firstNumber).rjust(length)
bottom = operator + str(secondNumber).rjust(length = 1)
lines = ""
res = str(sum).rjust(length)
for s in range (length):
line += "-"
if problem != problems[-1]:
first += top + " "
second += bottom + " "
lines += line + " "
sumx += res + " "
else:
first += top
second += bottom
lines += line
sumx += res
if solve:
string = first + "\n" + second + "\n"+ lines + "\n"+ sumx
else:
string = first + "\n" + second + "\n"+ lines
return string
i do not under stand why my code is wrong
Please provide some information on what the problem is. Ideally, share some error messages.
Sharing your code usually would also be ideal. But you posted a link to a replit, where the main.py
content got deleted. If this is your actual code, you need to go to the challenge page, get a new template and copy-paste the content of the main.py to your project.
Well, the error from this link it’s you or some error occurred and erase the main.py,
If you have a new link with your code and with the main.py fixed, please, try to show that new one
That if condition it’s not useful, because if the error it’s the operator, will return the first if, because the return it’s in the same indentation
if(re.search("[^\s0-9.+-]",problem)):
if(re.search("[/]", problem) or re.search("(*)", problem)):
return "Error: operator must be '+' or '-'."
return "Error: Numbers must only contain digits."
I suggest you take the if operator out of the if for numbers, And I also think it would be easier for you if you first tested all kinds of errors that way and then started working to create the calculator.
if(re.search("[^\s0-9.+-]",problem)):
return "Error: Numbers must only contain digits."
elif(re.search("[/]", problem) or re.search("(*)", problem)):
return "Error: operator must be '+' or '-'."
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.