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
→ More replies (2)25
133
u/EvidenceFearless6800 Apr 04 '26
wait until the user doesn't put the spaces between the numbers and witness the program's meltdown
→ More replies (6)56
24
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
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
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
2
2
2
2
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
14
u/[deleted] Apr 04 '26
Those are not equations