r/PythonCircleJerk • u/denehoffman • Dec 25 '25
greatest scripting language I’m 13 and just made my first Python calculator
Check out the code here (I’m 13):
```python
if __name__ == ‘__main___’:
print(eval(input(“Enter math: “)))
```
Supports all arithmetic and even parentheses! Any recommendations? Did I mention I’m 13?
2
u/BeautifulMortgage690 Dec 28 '25
LMAOO for a moment i thought the viewfarming bot made an alt account since people were calling it out
1
u/denehoffman Dec 28 '25
Hahahaha
1
u/BeautifulMortgage690 Dec 28 '25
please plug in a yt link unprompted
2
u/denehoffman Dec 28 '25
2
u/BeautifulMortgage690 Dec 28 '25
i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it i knew it
2
2
u/Osleg Dec 28 '25
I've bet, and won, with lots of people, that I am able to write a complete calculator with 2 lines of code. Now it's your turn to bet and win! 😉
1
u/denehoffman Dec 28 '25
Technically you only need one line, I added the ifmain for shits and giggles
2
u/Osleg Dec 28 '25
You also need to "from math import *" to have it really catch it all calculator, else it just basic functionality.
1
u/denehoffman Dec 28 '25
I think you can just load that in the input, it should handle semicolon-separated entries, but I haven’t checked
2
4
1
u/Duck_Devs Dec 27 '25
call me a germaphobe the way I STRONGLY recommend sanitation
1
1
u/denehoffman Dec 27 '25
\uj what do you guys think is the minimum character set that would allow both arithmetic and also arbitrary code execution?
1
u/Duck_Devs Dec 27 '25
What I did for my math parser backed by eval, was I heavily modified the input so that I could do things like implicit multiplication (ab = a*b) with exceptions for allowed functions (like log) which sanitized the input as a byproduct.
1
u/denehoffman Dec 27 '25
That makes sense, I was thinking more along the lines of, if I allowed someone to enter arbitrary text but filtered on a set of allowed characters, what characters would have to be permitted. I came up with “evalopn’.rd” plus parentheses so you could inject “eval(open(‘a’).read())”
2
u/Duck_Devs Jan 02 '26
Eval and exec allow you to provide a restricted scope, or set of accessible variables. You might be able to completely disallow the powerful built in functions like open but allow math functions like log, without having to have a restricted character set.
1
u/Ambitious-Star9136 Dec 27 '25
You can do other things with Statistics and maybe calculus if you have learned it.
1
1
u/Spiritual_Sun_4297 Dec 27 '25
I don't want to be mean, but there's nothing special in being 13 and doing python... I mean, I understand how that can be viewed as a hacker thing, in some places. But on the internet... Not really...
Rather, it's great that you started coding! Maybe its gonna be come your passion, or even just your job. Nevertheless, some other users commented about code injection. It's some neat stuff.
I would suggest to study some more and make a proper program. 'eval' is a very dangerous function, but don't bother with it for now. Just don't use it and one day you will probably understand why, if you keep studying.
You can start with the official tutorials guide
1
u/denehoffman Dec 27 '25
This was meant as a bit, there’s a guy posting on r/pythonlearning who starts all his posts with “I’m 13”. I figured this sub was meant for unserious posts about Python, but I seem to be wrong about that 😂
2
u/Spiritual_Sun_4297 Dec 27 '25
Oh shoot! I didn't notice the subreddit! That's funny now 🤣🤣🤣🤣
1
u/denehoffman Dec 27 '25
Haha you’re not alone, I feel like most of the comments here were taking me seriously, Poe’s law strikes again
1
u/Cokalhado Dec 28 '25
How old are you btw? (if you were younger than 14 it'd be very impressive), I'm 13
1
1
u/Socialimbad1991 Dec 26 '25
Neat! You should host it on a server to show off your work
1
3
u/TroPixens Dec 25 '25
Can I have access to your computer so I can calculate this problem
Sudo Rm -rf —no-preserve-root /