Diamond exercise

Helo, I find something odd in the Diamond exercises:

What the exercise describes:
----A----
—B-B—
–C—C–
-D-----D-
E-------E
-D-----D-
–C—C–
—B-B—
----A----

What the exercise actually expects:
[" A “, " B B “, “C C”, " B B “, " A “][”–A–”,-”-B-B-”,-“C—C”,-“-B-B-”,-“–A–”]
(with spaces I know)

Based on the task description I would had expected a single string to be submitted, with \n breaks, but the task actually wanted lists, which are not Diamond shaped upon printing at all.

Is it my broken English or is the task really not alligned between the description (readme) and the test expectations?

I submitted a solution which worked in my pycharm but the online Exercism does not accept it. (requested mentoring)

Sorry if this is something trivial I am missing, I am new here.

The description lays out the problem in general. The tests contain the specifics of what needs to actually happen. See Test Driven Development | Exercism's Docs

It sounds like either something is broken or you’re writing code but not actually running the unit tests in your local environment! See Testing on the Python track | Exercism's Docs

I ran and posted several exercises the same way. :-(

Those docs apply to all the exercises. Did you read them? Do they answer your questions?

I can only repeat that on my pycharm the tests succeed and I tested and submitted exercises this way about two dozen times by now and they worked. For some reason and I tried to resubmit it this one do not.

I try to insert screenshots.

You’re running pytest locally and it passes but the tests on the website fail? Can you share the test failures message from the website (using a codeblock and NOT an image)?

AN ERROR OCCURRED

We received the following error when we ran your code:

  .usr.local.lib.python3.11.site-packages._pytest.python.py:618: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
.usr.local.lib.python3.11.site-packages._pytest.pathlib.py:533: in import_path
    importlib.import_module(module_name)
.usr.local.lib.python3.11.importlib.__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
.usr.local.lib.python3.11.site-packages._pytest.assertion.rewrite.py:168: in exec_module
    exec(co, module.__dict__)
.mnt.exercism-iteration.diamond_test.py:7: in <module>
    from diamond import (
E     File ".mnt.exercism-iteration.diamond.py", line 6
E       diamond = f"{" " * where}A{" " * where}\n"
E                                                 ^
E   SyntaxError: f-string: expecting '}'

def rows(letter):
abc = “abcdefghijklmnopqrstuvwxyz”.upper()
where = abc.index(letter)
size = max(where * 2 + 1, 1)

diamond = f"{" " * where}A{" " * where}\n"

for build in range(size - 2):
    diamond += f"{" " * size}\n"

if where > 0:
    diamond += f"{" " * where}A{" " * where}\n"

size += 1

for count, build in enumerate(range(size, size * (where + 1), size)):
    position = build + where - count - 1
    diamond = f"{diamond[:position]}{abc[count + 1]}{diamond[position + 1:]}"
    position = build + where + count + 1
    diamond = f"{diamond[:position]}{abc[count + 1]}{diamond[position + 1:]}"

for count, build in enumerate(range((size * (size - 2)), (size * (round(size / 2)) + 1), -size)):
    position = build - where + count - 1
    diamond = f"{diamond[:position]}{abc[count + 1]}{diamond[position + 1:]}"
    position = build - where - count - 3
    diamond = f"{diamond[:position]}{abc[count + 1]}{diamond[position + 1:]}"

print(f"\n{diamond}\n")

diamond = diamond.replace("\n", "")
size -= 1

diamond_list = []

for rebuild in range(0, len(diamond), size):
    diamond_list.append(diamond[rebuild:rebuild+size])

print(diamond_list)

return diamond_list

It looks like you have a syntax error on this line. I believe you are using a Python 3.12 feature but Exercism runs Python 3.11.

That is strange I am fairly certain I used f" before.

For example the following line is from another exercise which passed the tast:
final = final + f"{combined_record_group[goin]}\n"

As @IsaacG pointed out, the problem is

f"{" " * where}A{" " * where}\n"

It uses the double quotes (") for the string and for the {} expressions inside the string.
This feature is “Quote Reuse” and has been added to Python in version 3.12 (see What’s new).

But Exercism’s test runner uses Python 3.11, so you get an error when you submit it to Exercism.