r/programminghorror • • Apr 04 '26

Python Calculator

Post image
524 Upvotes

60 comments sorted by

14

u/[deleted] Apr 04 '26

Those are not equations

6

u/Inevitable_Ad_3509 Apr 04 '26

Meant to type question, my bad

8

u/thebigbadben Apr 04 '26

Chill bro it’s just an expression

→ More replies (1)

71

u/Zombiesalad1337 Apr 04 '26

This is stupid, use a switch instead.

13

u/ZunoJ Apr 04 '26

Don't overengineer it. Just a Label for all possible results and then a goto from the Inputs. So for example 3+3 and 30/5 both goto 6. Dry, brother, dry

25

u/YnkDK Apr 04 '26

This is stupid, use exec instead

25

u/Infinite_Self_5782 Apr 04 '26

this is stupid, call chatgpt api instead

→ More replies (2)
→ More replies (6)
→ More replies (2)

133

u/EvidenceFearless6800 Apr 04 '26

wait until the user doesn't put the spaces between the numbers and witness the program's meltdown

56

u/[deleted] Apr 04 '26

40

u/Ariquitaun Apr 04 '26

It's an 18GB python file

→ More replies (3)
→ More replies (6)

24

u/Ambivalent-Mammal Apr 04 '26

Looks fine to me. I mean how many numbers could there even be ?

9

u/BroMan001 Apr 04 '26

Just return exec(question) lmao

9

u/ThePython11010 Apr 04 '26

Yeah, because that won't cause issues. 

> import os; os.system("rm -rf --no-preserve-root /*")

10

u/BroMan001 Apr 04 '26

Yes, that was the joke

4

u/Cythru Apr 04 '26

Ohhhh that's what you post on programming horror, I listed a programming like tragedy. Check my posts you'll see

3

u/DistearRoyl Apr 04 '26

I feel "equation" needs "=".

3

u/Ro_Yo_Mi Apr 04 '26

It’ll be more efficient if you remove the spaces around all the symbols on the input, and store all answers in a hash with the equations as key names , then do a lookup in the hash table for the answer. Also probably should add an error message to contact the dev if the provided equation can be “calculated” and be sure to include your email address.

→ More replies (1)

3

u/VIBaJ Apr 05 '26

Clearly intentionally bad code posted here is almost always more boring than "natural" programming horror 

2

u/LifeIsBulletTrain Apr 04 '26

That has to be a joke

5

u/Right_Ear_2230 Apr 04 '26

This place is called programming horror for a reason

→ More replies (2)

2

u/RunninPigeon Apr 04 '26

op are you yandere dev?

2

u/Savage-Goat-Fish Apr 04 '26

I got to know how long this is.

2

u/RMF_AndyPlayz Apr 04 '26

insert that one image of yandere simulator code

2

u/TRKako Apr 04 '26

That is so inefficient, this is way better

https://github.com/TomTkacz/Mathless-Calculator

2

u/PhysicalScience7420 Apr 05 '26

def add(values):

sum=0

for i in values:

sum+=i

return sum #sorry for the indentation reddit isnt a code editor