Scientific Computing with Python Projects - Arithmetic Formatter

Tell us what’s happening:
Describe your issue in detail here.

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/113.0.0.0 Safari/537.36

Challenge: Scientific Computing with Python Projects - Arithmetic Formatter

Link to the challenge:

I got error on replit. def arithmetic_arranger(problems, solve=False):
if len(problems) > 5:
return “Error: Too many problems.”

first_line = “”
second_line = “”
third_line = “”
fourth_line = “”
for problem in problems:
problem = problem.split()

  if problem[1] != "+" and problem[1] != "-":
      return "Error: Operator must be '+' or '-'."

  if not problem[0].isdigit() or not problem[2].isdigit():
      return "Error: Numbers must only contain digits."

  if len(problem[0]) > 4 or len(problem[2]) > 4:
      return "Error: Numbers cannot be more than four digits."

  if problem[1] == "+":
      answer = int(problem[0]) + int(problem[2])
  else:
      answer = int(problem[0]) - int(problem[2])

  length = max(len(problem[0]), len(problem[2])) + 2
  first_line += problem[0].rjust(length) + "    "
  second_line += problem[1] + problem[2].rjust(length - 1) + "    "
  third_line += "-" * length + "    "
  fourth_line += str(answer).rjust(length) + "    "

if solve:
arranged_problems = first_line.rstrip() + “\n” + second_line.rstrip() + “\n” + third_line.rstrip() + “\n” + fourth_line.rstrip()
else:
arranged_problems = first_line.rstrip() + “\n” + second_line.rstrip() + “\n” + third_line.rstrip()

return arranged_problems

My code works on local

Sorry i copy the wrong code. I got this error when i run my code on replit

Traceback (most recent call last):
File “main.py”, line 2, in
from pytest import main
ModuleNotFoundError: No module named ‘pytest’

try going to the console and typing “pip install pytest”

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