This is one place. I didn’t scour your code for every instance.
could you tell me how to make it correct
A else
or elif
has to be at the same indentation as its if
.
sum = ""
if (operator == "+"):
sum = str(int(firstNumber) + int(secondNumber))
elif(operator == "-"):
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 mustonly 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 must only contain 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’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).
What errors are you seeing now? What have you tried to fix them?
yes but it keeps saying the same thing so i do not know where is wrong
You have not yet described what’s happening yet, so I can’t know what it’s saying to you.
return"error: Numbers mustonly contain digits."
but i have changed it to must not
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