Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:
Replit keeps saying theres a syntax error and i can’t figure out where. I though it was in the readme.md and I put a # there and the error went away. Now whenever I click run theres no output whatsoever

Your code so far

def arithmetic_arranger(problems, val=False):
    arranged_problems = ''
    if len(problems) > 5:
        arranged_problems = "Error: Too many problems."
        return arranged_problems

    # list of all operations in str format
    operations = list(map(lambda x: x.split()[1], problems))
    if set(operations) != {'+', '-'} and len(set(operations)) != 2:
        arranged_problems = "Error: Operator must be '+' or '-'."
        return arranged_problems

    numbers = []  # list of all operands in str format
    for i in problems:
        p = i.split()
        numbers.extend([p[0], p[2]])

    if not all(map(lambda x: x.isdigit(), numbers)):
        arranged_problems = "Error: Numbers must only contain digits."
        return arranged_problems

    if not all(map(lambda x: len(x) < 5, numbers)):
        arranged_problems = "Error: Numbers cannot be more than four digits."
        return arranged_problems

    top_row = ''
    dashes = ''
    values = list(map(lambda x: eval(x), problems))
    solutions = ''
    for i in range(0, len(numbers), 2):
        space_width = max(len(numbers[i]), len(numbers[i+1])) + 2
        top_row += numbers[i].rjust(space_width)
        dashes += '-' * space_width
        solutions += str(values[i // 2]).rjust(space_width)
        if i != len(numbers) - 2:
            top_row += ' ' * 4
            dashes += ' ' * 4
            solutions += ' ' * 4

    bottom_row = ''
    for i in range(1, len(numbers), 2):
        space_width = max(len(numbers[i - 1]), len(numbers[i])) + 1
        bottom_row += operations[i // 2]
        bottom_row += numbers[i].rjust(space_width)
        if i != len(numbers) - 1:
            bottom_row += ' ' * 4

    if val:
        arranged_problems = '\n'.join((top_row, bottom_row, dashes, solutions))
    else:
        arranged_problems = '\n'.join((top_row, bottom_row, dashes))
    return arranged_problems

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

What error says exactly? Could you link to your replit?

1 Like

You should paste the Error as well here to make it more clear.

I’ve edited your code 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 (').

Hi! Sorry for the late response. It says this:
Traceback (most recent call last):
File “main.py”, line 2, in
from pytest import main
ModuleNotFoundError: No module named 'pytest’Here’s the link: Sign Up - Replit

Hi! Sorry for the late response. It says this:
Traceback (most recent call last):
File “main.py”, line 2, in
from pytest import main
ModuleNotFoundError: No module named 'pytest’Here’s the link: Join CruelSeeker1002's "boilerplate-arithmetic-formatter (1)" - Replit

It was missing the Pytest module in your Environment, I have Installed it through
pip install pytest command in the Shell to make the environment running. It is working fine now.

ahh. thanks mate. I was wondering what the problem was.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.