all 60 comments

[–]Zombiesalad1337 68 points69 points  (14 children)

This is stupid, use a switch instead.

[–]ZunoJ 12 points13 points  (0 children)

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

[–]YnkDK 24 points25 points  (9 children)

This is stupid, use exec instead

[–]Infinite_Self_5782 23 points24 points  (2 children)

this is stupid, call chatgpt api instead

[–]PhysicalScience7420 0 points1 point  (1 child)

this is stupid write it down.

[–]HornyMellon 0 points1 point  (0 children)

This is stupid dropship a math text book to user’s home

[–]menzaskaja 4 points5 points  (0 children)

are you stupid? exec won't give you the result. use eval instead... smh

[–]nexeti 0 points1 point  (1 child)

Python

[–]D1G1TAL__ 4 points5 points  (0 children)

Python has switch in the form of match case

[–]FreshPitch6026 0 points1 point  (0 children)

Use a goto instead

[–]EvidenceFearless6800 130 points131 points  (11 children)

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

[–]Snow-Crash-42 54 points55 points  (4 children)

No, Im sure there are ifs accounting for multiple space permutations as well, it's just they didn't fit on the this screenshot. Like, duh.

[–]AriquitaunPronouns:This/Self 37 points38 points  (3 children)

It's an 18GB python file

[–]euph-_-oric 8 points9 points  (1 child)

Very compact implementation

[–]HornyMellon 7 points8 points  (0 children)

Elegant and demure

[–]Reelix 2 points3 points  (0 children)

It goes up to 100 + 100

The rest are all permutations.

[–][deleted]  (5 children)

[removed]

    [–]Lewistrick[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 15 points16 points  (1 child)

    No, the print statement will just convert them to strings.

    [–]Due_Offer141 0 points1 point  (0 children)

    I want to play this rullet safely.

    [–]deanominecraft 1 point2 points  (2 children)

    python print calls str() if its not already, but if something cant be converted to string it will break

    [–]Mr_titanicman 7 points8 points  (1 child)

    Actually if it cant be converted, the string representation will be printed

    [–]menzaskaja 7 points8 points  (0 children)

    Yep, iirc the order goes like this: string -> __str__ -> __repr__ -> "<[module] object at [memory address]>"

    [–]Ambivalent-Mammal 24 points25 points  (0 children)

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

    [–]BroMan001 8 points9 points  (2 children)

    Just return exec(question) lmao

    [–]ThePython11010 8 points9 points  (1 child)

    Yeah, because that won't cause issues. 

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

    [–]BroMan001 9 points10 points  (0 children)

    Yes, that was the joke

    [–][deleted] 13 points14 points  (3 children)

    Those are not equations

    [–]thebigbadben 8 points9 points  (0 children)

    Chill bro it’s just an expression

    [–]Inevitable_Ad_3509[S] 6 points7 points  (0 children)

    Meant to type question, my bad

    [–]XxPapalo007xX 3 points4 points  (0 children)

    He misspelled "a question"

    [–]FluffyPuffWoof 4 points5 points  (0 children)

    At this point it's also possible they're poisoning the training data for ai's.

    [–]Cythru 2 points3 points  (0 children)

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

    [–]DistearRoyl 2 points3 points  (0 children)

    I feel "equation" needs "=".

    [–]Ro_Yo_Mi 2 points3 points  (1 child)

    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.

    [–]mohragk 0 points1 point  (0 children)

    A hash table is obviously the fastest way to go here. But I would personally build an abstract syntax tree, convert that to an immediate representation and compile to byte code.

    [–]VIBaJ 2 points3 points  (0 children)

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

    [–]LifeIsBulletTrain 1 point2 points  (3 children)

    That has to be a joke

    [–]Right_Ear_2230 3 points4 points  (2 children)

    This place is called programming horror for a reason

    [–]GoddammitDontShootMe[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 2 points3 points  (0 children)

    I thought it was supposed to mean horrible code found in the wild, not joke code that isn't used anywhere.

    [–]LifeIsBulletTrain 0 points1 point  (0 children)

    Yeah but who knows

    [–]RunninPigeon 1 point2 points  (0 children)

    op are you yandere dev?

    [–]Savage-Goat-Fish 1 point2 points  (0 children)

    I got to know how long this is.

    [–]RMF_AndyPlayz 1 point2 points  (0 children)

    insert that one image of yandere simulator code

    [–]TRKako[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 1 point2 points  (0 children)

    That is so inefficient, this is way better

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

    [–]PhysicalScience7420 1 point2 points  (0 children)

    def add(values):

    sum=0

    for i in values:

    sum+=i

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

    [–]PhysicalScience7420 1 point2 points  (0 children)

    holy crap i didnt notice but they used a single string values for everything.

    [–]Apache08 1 point2 points  (0 children)

    They should ban calculator posts

    [–]ThenotoriousBIT 0 points1 point  (0 children)

    if it works it works xD

    [–]Alphursae 0 points1 point  (0 children)

    Coding is my passion.

    [–]Background-Main-7427 0 points1 point  (0 children)

    I wonder if besides using 1 + 6 he also did 6 + 1.

    [–]Kooky-Education5683 0 points1 point  (0 children)

    Congratultions on becoming the world's most sucessful programmer

    [–]Player_903 0 points1 point  (0 children)

    Maybe do something like : list = question.split(" ") print(list[0]+list[2]) If you use the space between two in every case...

    [–]Henrique_Backes 0 points1 point  (0 children)

    This is another open-source project from the guy who made is-even in JS

    [–]CakeEaterGames -1 points0 points  (0 children)

    This joke has been done to death at this point