Arithmetic Arranger(Scientific Computing with python)Feedback Appreciated

Hey! Programming noob here. This is the first time I have worked this hard on a program and it is also the longest script that I wrote on my own yet. I thought it would be easy to do it but there were so many hassles in the way that I did not expect(especially with the test module being so stingy with the spaces and enters). But it is finally completed. I know this is pretty basic but its a start for my journey! I would really appreciate any kind of advise on my coding because it is probably very inefficient.

My plan was simple:-

  1. Create a 2d list containing all the numbers
  2. Make and return a string complying with the rules using the 2d list.

It sounded so simple in my head but it wasn’t because of my noob skillz…

https://repl.it/@CalmMango/fcc-arithmetic-arranger

Hey good job with your code!

I didn’t go through everything, but I noticed one logical error in your code that I wanted to point out:
When you were checking that the operators matched, you checked to make sure that “*” and “/” were not in the inputted string. It makes more sense to just check that the operator is only “+” or “-”. The reason being is because if some other operator was passed in (e.g, %, **, or any typo) your code would not be able to handle it.

I hope this could be of some help

Cheers

Michael

2 Likes

Ah yes… that way the code would be way less vulnerable against blowing up. Thank you very much for your input.

I think going with the 2d list approach is little lengthy to program
Your exception handling is clever I liked it.
I use the right align function string.rjust(width,fill_charater)

this is my repl: - repl.it repository

1 Like

First of all, thank you for going through my code! I really appreciate it. I agree with you after seeing your code that my approach was unnecessarily lengthy. Your code handled the problem much more elegantly than mine and I learned a lot from it. Thanks for introducing me to rjust() func. It could have saved me from that “maxim” cringe in my code if I knew about it lol. Though I am glad you liked my exception handling.

1 Like