This is a bad idea - what if someone did something like this: Calculator("+ 0;", "0 ", "print('Thanks eval')")? It may be shorter but you have just opened up this simple program to vulnerabilities.
This is a bad calculator since there is no lexical analysis (input would be "10 + 10"). Try making it better and expand on it so it supports powers (**), lets you use more that one expression ("10 + 10 / 2) WITH the order of calculation. Sure you can do some good things with it.
@JefeThePug: if you post code, better to fork the kumite.
eval is unsafe, avoid using it
Fair enough reasoning, I suppose.
If its software running locally, its fine. I would not reccomend this for networked applications.
This is a bad idea - what if someone did something like this:
Calculator("+ 0;", "0 ", "print('Thanks eval')")
? It may be shorter but you have just opened up this simple program to vulnerabilities.yeah, I saw it, eval based solution is kinda first that comes to mind and considers vulnerable, I'd like to show another options
Glad you like my solution, Ive made an improved version below, that uses eval. So it's less code and makes more operators available.
right,
reduce
can be rid of.This is a bad calculator since there is no lexical analysis (input would be
"10 + 10"
). Try making it better and expand on it so it supports powers (**), lets you use more that one expression ("10 + 10 / 2
) WITH the order of calculation. Sure you can do some good things with it.