Thanks of gratitude, Moving on to next project

I’m so so happy right now…
I just finished completing the ‘arithmetic calculator’ project in freecodecamp and I’m just feeling a sense of accomplishment right now
Special thanks to @kevinSmith and @Jagaya for making this a success…

Here’s a link to my code (https://replit.com/@97598311FC/boilerplate-arithmetic-formatter-9#arithmetic_arranger.py)…

I would also like to know better and shorter ways to write this code if possible

Moving on now to the next project :grin:
‘Time Calculator’ , Here I come!!

7 Likes

For a start, if you got if-else, but nothing in one block, consider changing the condition so you only have an if-block.

#instead of
if(x>5):
  pass
else:
  #some code

#do
if (x<=5):
  #some code

Then consider using max() to get the longer number, instead of writing two cases depending on which number is longer.
On top of that the operator only changes if you add or subtract the two numbers, so you should only change the calculation of the result → right now you have almost identical code twice.

On top of that if(-)-elif(+)-else(pass) is redundant. You already checked that the operator is either + or -. That means you only need if(+)-else, because if it isn’t +, it has to be -.

Finally, on the note of repeated code: given the thing you return is definitly 3 lines and the boolean only determines if the 4th line is added, here you could just combine the 3 lines and then have an if() to maybe add the 4th line and then return the result.
This makes it more obvious for a reader that the boolean only changes the last line and nothing else.

1 Like

Thanks…
I do appreciate…
I’ll try amending it

1 Like

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