Arithmetic Formatter question

I am starting out with Python and I know data types, functions, loops, etc.
My problem is that I am lost when it comes down to creating code from scratch. I can generally read it.
This took me hours to put together yet I’m not even close to solving the the “Arithmetic Formatter” you have on your website.

arith = ["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]
global_list = []

for i in arith:
    new_list = i.split(" ")
    global_list.append(new_list)

print ("  ", global_list[0][0], global_list[1][0], " ", global_list[2][0]," ", global_list[3][0])
print (global_list[0][1], global_list[0][2], "",global_list[1][1], global_list[1][2], global_list[2][1], global_list[2][2], global_list[3][1], global_list[3][2])
print (int(global_list[0][0]) + int(global_list[0][2]))

Source: https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/arithmetic-formatter

Hi, I’ve moved this into it’s own thread. Also, when you post, be sure to include a link to the challenge. I’m not a python guy, but I’m sure one will be along shortly.

1 Like

Well, no one has answered, so I’ll give it a whack. (Keep in mind, I don’t know Python.)

Yes, learning take the tools that we’ve learned and to break these things into small steps and work through it.

The first thing is to understand that algorithms are not computer programming. An algorithm is not tied to a specific programming language or any programming language. If an alien asked me “What is a fool proof method for finding the right page in the dictionary for a specific word?” I would say:

  1. Open up halfway through the book, essentially dividing it into two sections
  2. See if the word you need comes before that page or after.
  3. If the word comes before, the “before” section is your new section, if it comes after, the “after” section is your new section.
  4. Go back to step 2 with your new section and repeat until you’ve divided it down to one section.

That is an algorithm, it is a process for solving a problem. This specific algorithm is called a binary search. How you implement that in every computer language will be slightly different, but the algorithm itself is language agnostic.

The other thing to know is that algorithms are hard - they take time to learn. The more you learn, the easier they get. Also, it is only a part of being a good programmer - don’t obsess about it. Just keep working at it - it will come.

What are the steps to this problem? Sit down and think it out. If you can write them out, even better - don’t worry about the specifics of Python, just write out the process. Some people then use pseudo-code, sort of a loose code that looks like a computer language, but isn’t strict. Being able to mentally conceive of the process is 80% of the problem.

Seriously, do that know. Reread the instructions, look at your input data, look at your desired data, and then figure out the steps. Again, don’t worry about Python.

I have an idea in my head but I want to let you figure it out.

I will say that:

print ("  ", global_list[0][0], global_list[1][0], ...

I don’t think that is going to work. How will you know how many math problems there are? When you have a list like that and you don’t know how many there are, usually you have to use a loop.


But take a second, think it out. Write out what you think the process is. Don’t worry about using the “perfect words”, just write out a process. Let us see what you come up with.

Thanks for your reply, I will get my head down again and follow your advice!
I am glad you didn’t share your code to solve the issue, I want to get going in my own syntax.

1 Like

Give it a shot and check back if you get blocked again. Everyone here knows how hard this is.