Hello I suck:
I wrote something for the arithmatic arranger but it only lasted six tests and I cant make sense of the return message. I have Copied below the message, I can attach a sample of my code that works if ran on shell or terminal.
======================================================================
FAIL: test_arrangement (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-11/test_module.py", line 10, in test_arrangement
self.assertEqual(actual, expected, 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]')
AssertionError: ' 3\t 3801\t 45\t 123\t\n+ 855\t- 2\t[39 chars]__\t' != ' 3 3801 45 123\n+ 855 -[52 chars]----'
- 3 3801 45 123
- + 855 - 2 + 43 + 49
- _____ ______ ____ _____ + 3 3801 45 123
+ + 855 - 2 + 43 + 49
+ ----- ------ ---- ----- : Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]
======================================================================
FAIL: test_only_digits (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-11/test_module.py", line 34, in test_only_digits
self.assertEqual(actual, expected, 'Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."')
AssertionError: 'Error: Numbers must contain only digits' != 'Error: Numbers must only contain digits.'
- Error: Numbers must contain only digits
? -----
+ Error: Numbers must only contain digits.
? +++++ +
: Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."
======================================================================
FAIL: test_solutions (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-arithmetic-formatter-11/test_module.py", line 39, in test_solutions
self.assertEqual(actual, expected, 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithmetic problems and a second argument of `True`.')
AssertionError: ' 32\t 45\t 123\t\n- 698\t- 3801\t+ 43\t+[66 chars]72\t' != ' 32 1 45 123\n- 698 - 3[84 chars] 172'
- 32 45 123
- - 698 - 3801 + 43 + 49
- ______ _______ ____ _____
- -666 -3800 88 172 + 32 1 45 123
+ - 698 - 3801 + 43 + 49
+ ----- ------ ---- -----
+ -666 -3800 88 172 : Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with arithmetic problems and a second argument of `True`.
----------------------------------------------------------------------
Ran 6 tests in 0.015s
FAILED (failures=3)
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
in the output there is a section where it confronts your result with the expected one, line by line: the lines starting with - are your code, the lines starting with + are the expected code
in the assertion error you can see it in raw form, the right part is the expected, the left is yours
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.
Hello thank you for the response, if it doesn’t harm the result how am I to do the spacing with out tab characters and such, also on average how long do students take to complete your cert for a good reality check.
you need to use spaces instead of the \t character, there is written in the descriptions how many spaces are expected
for the certificate, it depends - each cert is given an estimate of 300 hours (where 50h are given to the challenges and 50h to each project) but it’s really different person by person, so how much time you will need, that will be the time you need
thank you, that makes me feel like I havent failed yet. I will reread the section on spacing. Also do you know of any online study groups that your students do I dont have any exposure to developers and only want to learn.
I am attaching a copy of my recent submission, it works in testing and development but when run, The out put os exactly what is asked but I seem to be missing something import. I am sorry to ask this but please tell me what I’m doing wrong, I will replace the return statements with print. Please it works but i seem to be miscommunicating somehow. Also there is some fluff I haven’t removed yet, sorry for the formatting I dont know how to show it right. Thank you in advance.
def arithmetic_arranger(problems = list(), *args):
var1 = [0,"",{}]
var2 = [0,"",[]]
var3 = [0,"",({})]
var3[2]['values'] = []
var1[2]["max"] = []
var1[2]["difs"] = {}
templist = []
upperstr = ""
lowerstr = ""
border = ""
sums = ""
arranged_problems = ""
var1[2]["op"] = []
var3[2]["bad_ops"] = "*/x"
var3[2]["good_ops"] = "+-"
state = None
def cmp(v1,v2):
if v1 == v2:return v1-v2
if v1 > v2:return v1-v2
if v1 < v2:return v2-v1
if len(problems) > 5:
return "Error: Too many problems."
else:
for g in problems:
for h in var3[2]["bad_ops"]:
if h in g:
return "Error: Operator must be '+' or '-'."
for i in var3[2]["good_ops"]:
if i in g:
var1[2]["op"] += [[i,g.find(i)]]
var1[0] = max(len(g[:g.find(i)].strip()),len(str(g[g.find(i)+1:].strip())))
try:
var1[1] = f"{int(g[:g.find(i)])}"
var2[1] = f"{int(g[g.find(i)+1:])}"
var3[1] = f"{eval(g)}"
var2[0] = max(var1[0],len(var3[1]));
if len(var1[1]) > 4: return "Error: Numbers cannot be more than four digits."
if len(var1[2]) > 4: return "Error: Numbers cannot be more than four digits."
var3[2]['values'] += [[var1[1],var2[1],var3[1]]]
except:
return "Error: Numbers must only contain Digits."
var1[2]["max"] += [var2[0]]
for k in range(len(var1[2]["max"])):
var3[0] = var1[2]["max"][k]
templist.append([cmp(var3[0],len(var3[2]['values'][k][0])),cmp(var3[0],len(var3[2]['values'][k][1])),cmp(var3[0],len(var3[2]['values'][k][2]))])
for j in range(len(problems)):
upperstr += f" {' '*templist[j][0]} {var3[2]['values'][j][0]} "
lowerstr += f"{var1[2]['op'][j][0]} {' '*templist[j][1]}{var3[2]['values'][j][1]} "
border += f"--{'-'*var1[2]['max'][j]} "
sums += f" {' '*templist[j][2]}{var3[2]['values'][j][2]} "
for state in args:
if state == True:
arranged_problems += f"{upperstr}\n{lowerstr}\n{border}\n{sums}"
return arranged_problems
if len(args)== 0:
arranged_problems += f"{upperstr}\n{lowerstr}\n{border}"
return arranged_problems
You should return strings, not print them.
Once you got that, consider including either a link to your code or at least the error-messages. Because if it’s not such an obvious error, because otherwise you basically expect people to execute your code in their head and get whatever might be wrong.
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.
I should add this my third attempt to submit but the first was almost a year ago. What I’m trying to say is, I am getting the right answer and spacing when I test but I think my the formatting style is what im getting wrong when it tests it by return. I am not good enough to fully understand what I’m doing wrong.
So yeah, you need to learn to read error-messages. One is telling you that you spelled “digits” instead of “Digits”, another one that you are not returning a message when there are more than 4 problems.
But lets get to the big one, first three lines are from me.
Coloring is done automatically by the forum if formatted as code btw.
And that one is pretty straightforward thanks to that (and very hard to spot without it): You have a bunch of extra spaces.