Share your repls and programming experiences

← Back to all posts
THE BEST CALCULATOR ON REPL.IT *not clickbait*
henryeth

Finally, this took SO MUCH effort. FINALLY IT WORKS.

I present to the repl.it community:
The best calculator I have ever seen on repl.it (so the title could potentially have been clickbait unintentionally, I have not been around for that long...). Following a trio of connected calculators:

This excels them all in all areas. The closest one is Valdez's C++ one but this is far smaller and more efficient, as well as supporting a couple more operators. Do your worst - if you do find a bug, please PLEASE let me know in the comments, I really want this flawless. It will be harder to abuse than Valdez's (I saw what you community did to that comment section) because it will should ignore any invalid characters or valid characters in invalid positions. However, obviously, integer limit is still a problem :braces himself for upcoming abuse of calculator:. Any questions or suggestions (preferably questions) please write them in the comments.

P.S: Please work calculator PLEASE.

Thank you all so much this is by far the most cycles I have ever had!

Voters
maxina
JWZ6
nro2collaborate
CodeChaos58
XanthusPettitt
Simer00
LegendaryWolf
AxolotlBot
coderdude666
ch1ck3n
Comments
hotnewtop
KnightsOfAzgard

Overall nice calculator.
However, I have found an error in your calculator @henryeth - it cannot handle imaginary numbers (3 + 2i^2 etc.). However, imaginary numbers are a key area in algebra, so this can be called a major error.

Another graphical problem (an extra dot in the end):

It can also be improved by adding equation solvers with variables, like the online calculator https://www.symbolab.com/ of wolfram alpha.

henryeth

@KnightsOfAzgard This calculator isn't meant to do algebra at all. The second dot is a period but yes it can be confusing I will remove it.

KnightsOfAzgard

@henryeth Well, it wouldn't exactly be the best calculator on repl.it then... no offense...

henryeth

@KnightsOfAzgard I said it was the best calculator on repl.it that I have seen. First, notice the lack of the word "algebra"

and second, note the "that I have seen". Even excluding the second point as it is kind of cheaty, try and find me a better calculator that matches the first point on repl.it, or, even better, make one yourself. I would be quite happy to be educated on the matter...

KnightsOfAzgard

@henryeth 'Calculator' may not equal 'Algebra Calculator', but 'Algebra calculator' is a 'calculator' so I suggest you make that clear.

As for finding a better calculator, I take you up on that challenge. emilian1000000's calculator (https://repl.it/@emilian1000000/Mega-Calculator) can be seen as better because of the average command as well as calculations on '<' and '>'.

henryeth

@KnightsOfAzgard yes and that one is error-proof, ignores invalid characters and handles calculations that are more than "[number][operator][number]"! Oh hang on... it does none of those things

WILLIAMBAEWER

@henryeth gotem

henryeth

@WILLIAMBAEWER :D pretty much

Baconman321

@KnightsOfAzgard If algebra is so important, why don't you go make it yourself?

It's going to be really hard, as you will have to parse the variables as well as other concepts in algebra.

Expect no less than 500 lines of code for something as complicated than that...

henryeth

@Baconman321 FeEl ThE bUrN

Coder100

is it really a good calculator without making a programming language? @KnightsOfAzgard

Coder100

hm that one isn't working very well at all

@KnightsOfAzgard

henryeth

@Coder100 That one is terrible and only works for 2 numbers and one operation.

henryeth

@KnightsOfAzgard @WILLIAMBAEW @Baconman321 @Coder100 new version out now! Do more testing :mechanical laugh:

Baconman321

@henryeth What's new?

henryeth

@Baconman321 A few new operators atm (will be more), smaller and more efficient system, handling for multi-character unary operators coming soon.

Baconman321

@henryeth Don't forget scientific notation!

1e+10 is the same as 10000000000.

henryeth

@Baconman321 Python has that integrated already i don't need to do it.

Baconman321

@henryeth doesn't work for me tho

CoderKid365

@henryeth cool project

henryeth

@Baconman321 idk how python actually use it tbh but it should pop it in for big and small numbers I think

Baconman321

@henryeth no I mean add support for parsing scientific exponents.

henryeth

@Baconman321 I can't be bothered

henryeth

@Baconman321 Actually on second thoughts, I think I may

enterCheesyNameHere

@Baconman321 representing variables in variables is hard.

applicationUFO

Not Clickbait

Totally clickbait
FlaminHotValdez

I saw what you community did to that comment section

I love this community so much.

ShadowHoonter

It also doesn't seem to run negative numbers.

ShadowHoonter

It seems that parentheses don't work.

tarboldz

@ShadowHoonter Well you can write:

9*(12)
The answer is 108.0

It works for me.

Kudos

Nice calculator. If I was doing this I would just eval() it 😁

henryeth

@Kudos :D I agree:

best calculator ever.

FlaminHotValdez

@Kudos ...The whole point of this is to make a calculator that doesn't do eval and isn't "Input the operator" "Input one number" "Input another number"

also to beat mine. yes I'm salty
henryeth

@FlaminHotValdez there is some element of truth in that last bit... alas I admit it

FlaminHotValdez
randomguy222

@Kudos LOLL

henryeth

@randomguy222 @Kudos new version out now!

randomguy222

@henryeth why ping tho

randomguy222

@henryeth welp, looks like you fixed the order of operators

good job!

TravisRaney
TravisRaney
randomguy222
FlaminHotValdez

@Kudos

You: "If I was doing this I would just eval() it
Also you: makes a legitimate calculator without using eval()

Kudos

@FlaminHotValdez
🤣 Well I didn't want to be an @AJK4 because it would bring no value to the community.

FlaminHotValdez

@Kudos ouch roasted

[deleted]

finally, you got a ton of cycles @henryeth! And the code is sooooooooo complicated that....(what is the append thing over there? what are - char, and other crazy stuff?)

Whippingdot

The code is sooooo simple(not to be mean) @CaptinNeo

henryeth

@Whippingdot agreed. Simple but effective

X24

@CaptinNeo Append just adds something to the end of a list

henryeth

@X24 ikr

JBloves27
FlaminHotValdez

@henryeth damn I'm salty it's so much easier to do in python because of the lambdas. I challenge you to make a version of this without lambdas!

henryeth

@FlaminHotValdez It would be exactly the same - just bigger. It would just be replaced by a bunch if statements in the place where it calls the lambdas. I won't because it is pointless and, as you say, you are being salty :D.

FlaminHotValdez

@henryeth lol yeah at least I admit it though xD. Truth be told though I probably wouldn't be able to do it in Python at all because I'm bad at it because I couldn't find a method to do it w/o stacks.

henryeth

@FlaminHotValdez Just study the code you'll figure it out. I am (spoiler alert) working on a second version with a different, simpler, method.

FlaminHotValdez

@henryeth what the beep how is it possible to be simpler

henryeth

@FlaminHotValdez probs not really "simpler" but more "slightly longer yet more readable and using more straightforward concepts".

henryeth

@FlaminHotValdez Out now - turns out it is simpler as well as the last things I listed.

henryeth

@CaptinNeo @Whippingdot @X24 new version now out feel free to comment on this one too...

X24

@henryeth I didn't critique anything, just told the guy what append means...

This is injustice!!!

henryeth

@X24 "InJuStIcE" fixed

X24
TravisRaney
SilvermoonCat

@henryeth nice I suggest making a while loop though so that I can keep using without having to rerun, everything else looks good :D

henryeth

@SilvermoonCat that is done now in the new version (check it out still on this post)

[deleted]

lmfao

TomMalone

SIR 66X0 IS NOT 660

Smart0ne

I typed in 2+2/2x2 and it said the answer is 2.090909090909091.

BananaJellyfish

i got infinity!

BD103

On Valdez's Calculator:

On your calculator:

Quoting Coder100, "ah yes, math".

(No hate, ngl. I could never do this without eval()!)

FlaminHotValdez

@BD103 then you are bad. Use exec()

ShadowHoonter

I don't know why, but % don't work, it doesn't say invalid input, it will break.

henryeth

@ShadowHoonter it did that with all operations if you had operation followed by nothing at the end - fixed now.

[deleted]

BUG


Nice Calculator 😎
But...there is a bug.

henryeth

@XThacker FINALLY fixed that took too long... like almost an hour probs...

BobTheTomatoPie

now this is impressive python coding

henryeth

@BobTheTomatoPie wooooow big names are coming tysm

BobTheTomatoPie

np you deserve it! I would not be able to do this in python even back when I used to use it, I was worried to click on this cause i thought it would be another eval statement, but I was very wrong, this is just awesome @henryeth

henryeth

@BobTheTomatoPie LoL I can imagine that, someone making a post with this title and the start of this description, and upvoting it with 25 bots. And the code is just:

BobTheTomatoPie

yea lol, even CC did that once @henryeth

FlaminHotValdez

@BobTheTomatoPie Which CC? CyanCoding or CodingCactus?

BobTheTomatoPie

coding cactus @FlaminHotValdez

henryeth

@BobTheTomatoPie I finished the second version and it is now on this post.

BobTheTomatoPie

wow, keep it up dude! @henryeth

henryeth
ColePete

really good, minor suggestion, make it a loop to keep going like my calculator.

henryeth

@ColePete have done, and that feature is still in the second version that is now out.

TravisRaney
ColePete

@TravisRaney hi, i guess

TravisRaney

@ColePete how are you?

ColePete

@TravisRaney good you?

TravisRaney

@ColePete just making my movie story season 1 and needing help though, I got it in my team

ColePete

@TravisRaney ill help if you want

TravisRaney
XanthusPettitt

hi, im currently making a calculator that does, well everything and I could use some more help

BenCavanaugh

this should equal 1 or 16???

minishxp

You can't use variables :trololololo:

BenCavanaugh

:(

henryeth

@BenCavanaugh Think about it, did you genuinely expect that to work?

BenCavanaugh
Kudos

Does this using the shunting-yard algorithm? It certainly looks so.

Soccer135246

CANNOT HANDLE SQUARE ROOTS!

WILLIAMBAEWER

it didnt work >:0 @henryeth

tarboldz

Put -69*69/420
The answer should be negative, returns POSITIVE

Put 4^-0.5
The nnswer should be 0.5. Instead returns the number if the exponent were POSITIVE (this is, 0.5), returning TWO.

You shouldn´t be SO POSITIVE with your calculator, SIR HENRY.

InvisibleOne

Or, you could just like do this: print(eval(input("Enter you expression: "))) since python can do math

RhinoRunner

@InvisibleOne True, but statements like that can backfire.
Plugging in a user input to eval without making sure it is an equation first can let people read/write/create files, which is very bad.
If you inspect the code here, you can see how it won't run the eval if it's not an equation.

zplusfour

i tried to do quik mafs

ComicBro

You should make a ans option, so you can use your past answer as a number

TravisRaney
RishabTirupath1

One thing that could be improved on is floating-point math. It is hard for base-2 computers to do simple things like add 0.1 and 0.2, but you could try a workaround, like multiplying the float until it is an int.

jagnar

when you are using this (For example it says 5 plus 5 = 55) Could you please fix this.

dogsledding

@jagnar use the actual symbols for the equation (+,/,*,^, etc)