Tell us what’s happening:
Describe your issue in detail here.
Your code so far
# This entrypoint file to be used in development. Start by reading README.md
from pytest import main
from arithmetic_arranger import arithmetic_arranger
print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]))
# Run unit tests automatically
main()
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36 Edg/96.0.1054.53
If you honestly know nothing about anything that is going on with the problem, then you should go back to the first Python lesson and start over, or at least back to where you understand what is going on.
If (as I suspect) you understand some of it, then please let us know what specifically is confusing you. It is unrealistic for you to expect one of us to spend an hour explaining every concept associated with that challenge.
And as stated, learning how to figure out what you don’t know and learning how to convey that - that is a very important skill. Good devs aren’t just good at writing code, they’re also good at talking about code.
Tell us what’s happening:
Describe your issue in detail here.
Your code so far
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
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36 Edg/96.0.1054.53
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.
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.