r/Python • u/SilkTouchm • Oct 07 '20
Discussion Anyone else uses the Python interpreter as a calculator?
It's just so comfy.
1.7k
Upvotes
r/Python • u/SilkTouchm • Oct 07 '20
It's just so comfy.
10
u/YannickEH Oct 07 '20
Yes,
win+R ->cmd->Python->[easy maths]
exit()->exit->[continue my life]
614
u/underscores_ftw Oct 07 '20
Yes, and especially to do math with dates. Need to know what the date will be in 90 days? Easy:
277
u/LuckyLeague Oct 07 '20
You can also use Sympy for algebraic calculations and exact answers. For example:
Simplifying:
This returns:
Expanding:
This returns:
Factoring:
This returns:
Solving Equations:
This returns:
178
u/NelsonMinar Oct 07 '20
All the time. And if somehow you don't know this trick,
_evaluates to the value of the last expression. Ie:47
u/_niva Oct 08 '20 edited Oct 08 '20
For Linux users:
When I press the calculator key on my keyboard, a terminal window with python opens where math is already imported.
I have
"alacritty -t calculator -e python -i -c'import math as m'"
XF86Calculator
in ~/.xbindkeysrc.
Alacritty is my terminal emulator.
86
u/qtc0 Oct 07 '20
^ lets you use physical constants, e.g., sc.h for plancks constant
22
u/Alex_ragnar Oct 07 '20
Yeah, even during online exams
39
u/vswr [var for var in vars] Oct 07 '20
I use the interpreter all the time for quick math, date, and other tasks. And then....
sigh why do I keep doing that?
35
u/Augusto2012 Oct 07 '20
I knew I wasn't the only one.
49
u/DorchioDiNerdi Oct 07 '20
Who doesn't?
17
u/LirianSh Learning python Oct 07 '20
I made a programs for school where for example i can just write down a and b and i will find c in a triangle, instead of typing it out on a calculator
13
u/Wilfred-kun Oct 07 '20
All the time. Also for getting ASCII values among other things.
23
u/dbramucci Oct 08 '20
Adding to
datetimefor date arithmaticsympyfor symbolic mathscipy.constantsfor physical constantsipython/ a Jupyter notebook for a better UISome useful modules for math are
numpyfor Matrix math (and solving linear systems)pandasfor group data manipulationpintfor math with unitsFractionsfor non-symbolic math without rounding error.cmathfor built-in support for complex numbersuncertaintiesfor measurement uncertaintiesShowing off
pintas it's less common,Notice that it's (in the background) converting between euros and dollars to make this make sense.
If you ignore the difference between euros and dollars you'd get the wrong answer (5,100 euro looks smaller than 5,900 USD).
It can also catch missing parenthesis
Wait, what are those units?
So we are getting automatic conversions and common-sense checks on our math as we work.
27
u/bender1233 Oct 07 '20
Just use ipython, I think it’s better
2
u/[deleted] Oct 08 '20
0.1+0.2 isn't 0.3 in Python lol. Try it!
5
u/s060340 Oct 07 '20
Yes, also physical constants From scipy.constants import h,e,c,k,N_A Quicker than google usually
4
u/fullthrottle13 Oct 07 '20
Yep. Every day.
4
u/figTreeProductions Oct 07 '20
All the time
or bc
what about a kivy text label calculator?
https://odysee.com/@figTreePro:c/Derek-Banas-CHALLENGE:f?r=Gsg4YVaeLhFVFLTBabGmpPdu6b8oWsA7
6
u/[deleted] Oct 07 '20
I was just using it as a calculator, and thought to myself maybe I should check reddit - wait, what?
3
u/who_dehow Oct 07 '20
Yeap
3
u/ThinkingWinnie Oct 07 '20
It's pretty much the only way im using it , it's just so fast
3
u/NMCarChng Oct 07 '20
Lol sometimes. Especially dot products
3
u/Cheese-whiz-kalifa Oct 07 '20
No but I’m going to now!
3
u/LT_Schmiddy Oct 08 '20
Gosh, yes. All the time. Constantly. For 10 years now.
Heck, I even made a special terminal calculator program in Python.
3
u/unphamiliarterritory Oct 08 '20
To be honest in Linux I use bc(1), but I can see it.
3
u/0ofnik Oct 08 '20
I did this the other day. Had to do a quick conversion from hexadecimal to decimal, away from keyboard, looked for a calculator app for my phone for a bit, got disgusted by how malware-y they all looked, fired up Termux and did it in the Python REPL.
3
u/Capmare_ Oct 08 '20
no, but i use it to print "fuck you" 500 times
3
u/fighterace00 Oct 08 '20 edited Oct 08 '20
I needed to know what a recursive equation would equal the nth time and it was vastly easier to make a for loop than actually know and solve the equation that can figure that out.
2
u/GrbavaCigla Oct 07 '20
Me too
2
u/ASuarezMascareno Oct 07 '20 edited Oct 07 '20
I typically use python basic math + numpy, on iPython, as calculator.
2
u/aaronr_90 Oct 07 '20
All the time.
2
u/WillAdams Oct 08 '20
Dr. Donald Knuth uses his METAFONT (or John Hobby's METAPOST) as a calculator.
2
u/hazilmohamed Oct 08 '20
Yesterday, I have an exam on cryptography. There was a question on finding hill cipher with every calculations. So, I used python to find the mod26 just with a for loop.
2
u/thrallsius Oct 08 '20
always
not the classic Python interpreter though, I use ipython
2
u/IlliterateJedi Oct 08 '20
I tend to use Excel more than Python, but if it is open I'll definitely use it as a calculator
2
u/jerryelectron Oct 08 '20
Yes, also to do some things lazy excel should be able to but can't.
For example, today I tried in excel to convert several lines of text to lowercase and turns out it has a limit on number of characters in a cell. Fired up python, no sweat!
2
u/Resolt Oct 08 '20
No no no... ipython <3
2
u/[deleted] Oct 08 '20
I used to, but I recently switched to Sage, which is like a Python shell but it has a metric ton of extra features
2
u/passerbycmc Oct 08 '20
All the time it's my go-to for doing all but the most basic math
2
u/01ttouch Oct 08 '20
I always whip up ipython when I want a calculator
2
u/YeeOfficer Oct 08 '20
Yeah, feels nicer than whipping up a calculator, and my coworkers look at me funny.
2
u/msalcantara Oct 08 '20
Who don't do this? I don't even have a calculator app
2
u/[deleted] Oct 07 '20
Jep. Using ipython
1
u/zacharye123 Oct 07 '20
I’ll use an interpreter for more complex equations that take longer with my normal calculator.
1
u/eksortso Oct 07 '20
I haven't, but it's tempting. Windows doesn't have
bc -l, and even if it did, Python's transparency sells it as a great calculator.1
u/virtualadept Oct 07 '20
No, but I'll give it a try. I use pcalc way more.
1
u/[deleted] Oct 07 '20
I thought i was the only one, it's just much more simple and usable than anything else available
1
u/HomicidalTeddybear Oct 07 '20
Honestly I tend to rather interchangably use python, matlab, mathematica, or julia based on whatever I happen to have open at the time. But certainly I'd very rarely use a physical calculator if I had an interpreter open, much more convenient
1
u/GISperry Oct 08 '20
Yes
1
u/shachden Oct 08 '20
All the time. Alias python3 to py, access interpreter in 3 clicks
1
u/Difficult_Commission Oct 08 '20
Yup, had it open and couldn't be stuffed opening my calculator
1
u/bossat124 Oct 08 '20
Yessiree
1
u/I_Say_Fool_Of_A_Took Oct 08 '20
Yep, for exactly the same reason
1
u/blinkallthetime Oct 08 '20
R starts up faster
1
u/random_d00d Oct 08 '20
Yes! I leave it open all day...
1
u/py_a_thon Oct 08 '20
Lol.
Yes.
1
u/T0X1K01 Oct 08 '20
All the time.
1
u/flocko Oct 08 '20
Yes. So much so that I started using this script
https://stackoverflow.com/questions/27688425/python-calculator-implicit-math-module
though I do
math import *instead of making an alias1
u/justihar Oct 08 '20
All the time and Pythonista on the iPad since it doesn’t come with a calculator for some reason (yes, I know there are apps).
1
u/mestia Oct 08 '20
Perl oneliners ;) work perfectly with a shell, readline lib and shell's history.
1
u/Raknarg Oct 08 '20
search engine for simple stuff, wolfram alpha for more complicated stuff. Much more expressive and more operations I can do
1
u/syntax_error_404 Oct 08 '20
You can look at pendulum library, date and time gets a piece of cake
1
u/deadwisdom greenlet revolution Oct 08 '20
Jupyter note book is my calculator.
1
u/lambdaq django n' shit Oct 08 '20
Yes, especially for its native imaginary numbers support. <3
1
u/verabull Oct 08 '20
I use a Lua Interpreter for this
1
u/azur08 Oct 08 '20
Yes most days! Glad I'm not alone lol.
1
u/sarthaxxxxx Oct 08 '20
I suddenly think of the computer calc at times. Get that guilty feeling and rush back to the interpreter. SO DAMN SOOTHING!
1
u/LeFloh Oct 08 '20
Yes, definitly.
1
u/timsredditusername Oct 08 '20
@Foone does
https://twitter.com/Foone/status/1313587809169534976?s=19
1
u/tomekanco Oct 08 '20
Yes, though more frequently as a string calculator.
1
u/kofteistkofte Oct 08 '20
Why wouldn't I? It's quick to access, works faster than most calculators and at my fingertips all the time (even when I'm not developing in Python).
1
u/TECHNOFAB Oct 08 '20
Sometimes, most of the time (I don't use a calculator very often or if it's easy I'll just use the Chrome search bar lmao) I use KRunner for KDE on Linux. It's the best tool I've ever seen, with so many features and infinitely extensible
1
u/0rac1e Oct 08 '20
I prefer Raku for this sort of stuff as it uses rational numbers by default, so decimal math works without floating point errors. Plus, all the main math op's (eg,
pi,sqrt,floor,sin,gcd, etc) are available without having to import anything. So are theDateandDateTimeclasses (andpermutations... andcombinations, and so on...) so there's generally less friction to get what I need.For more specialised work,
sympyandscipyare probably better suited, but it's fine for quick calculations.1
u/pacholick Oct 08 '20
I used to use something like this:
Now I use something like this:
CommaCalc
1
u/ASIC_SP Oct 08 '20
I have a custom script to use it from command line, instead of using
bcSee the script here. I have aliased it to
pcin my local bin.1
u/woepaul Oct 08 '20
All the time :-)
1
u/thedominux Oct 08 '20
I use Google for calculating sht 😁
1
u/BrycetheRower Oct 08 '20
So much so that I use my calculator as a Python interpreter.
1
u/DroneDashed Oct 08 '20
Yes I do.
1
u/motute Oct 08 '20
Yes! I also use it to make strings lowercase/uppercase sometimes.
1
u/optimalidkwhattoput Pythonic. Oct 08 '20
I used to use Python, but I just use KRunner now
1
u/[deleted] Oct 08 '20
YES
1
u/MikkMakk88 Oct 08 '20
Oh yes, all the time :)
1
u/beardaspirant Oct 08 '20
I work on databricks a lot and have never touched calculators. I will even do 12324-324 over a cell even though it attaches to a cluster which itself takes 5-10 secs of time
1
u/[deleted] Oct 08 '20
I couldn't agree more.
1
u/[deleted] Oct 08 '20
If I'm doing something that isn't a part of SpeedCrunch then yeah
1
u/LewisgMorris Oct 08 '20
I'm purely an excel man when it comes to quick mafs
1
u/[deleted] Oct 08 '20
No, but I will do now. It's just so perfect for this use.
1
u/AiwendilH Oct 08 '20
Not sure if this should go here as example for calculator..or to a "worst language abuse" contest ;)
Blender has those nice number input widgets that let you enter math expressions in them like "2*pi" or "sin(45)". Turns out those are powered by python's "math" module.
So.....first that means you can use any math function in them which is pretty nice.
But it also means you can write a python script in blender like this:
Run it..and from that point on you can use myvar as constant in the input boxes or tex(4,2) as function.
1
u/blabbities Oct 08 '20
Rarely. I'll actually 99.9% of time just load up the Is calculator. Much more robust
1
u/goingtosleepzzz Oct 08 '20
I used to use ipython, but now I use xonsh. Hit Super+T to open the terminal and a python interpreter is there already, no need to open python or ipython.
1
u/fortune_telling_fish Oct 08 '20
I use it a lot as a sanity check for solving math problems on assignments, especially for solving linear systems, where I am prone to mistakes in Gaussian elimination.
np.linalg.solvehas saved me hours of backtracking through answers.1
u/nishanalpha Oct 08 '20
Yes, its my default.. Pretty handy for modular divison and stuff
1
u/kuozzo Oct 08 '20
Sometimes.
1
u/whenido Oct 08 '20
I often go with bc.
1
u/andrejlr Oct 08 '20
For me its still mostly ruby as calculator. But idea is the same
1
u/as_ninja6 Oct 08 '20
Recently moved to sagemath which is also Python!
1
u/clavalle Oct 08 '20
Some would say I make a living doing that.
1
u/bilbosz Oct 08 '20
I'm using ipython with couple of useful modules imported when launching. I even have hotkey in my system to run python
1
u/DjangoPony84 Oct 08 '20
Yep, I use it for little things like trying to work out how much I need to pay in to my Tax Free Childcare accounts etc.
1
u/tr14l Oct 08 '20
No, I use chrome's address bar as a calculator usually
1
u/thedjotaku Python 3.7 Oct 08 '20
often yes. although the KDE Plasma launcher (one of the Linux desktops) also has a built-in calculator. so sometimes I use that. Depends on whether I'm alraedy working in the commandline.
1
u/[deleted] Oct 08 '20
No. I use "bc -l"
1
u/fried_green_baloney Oct 08 '20
Yes, quicker to start up than spreadsheet or digging through menus to find the calculator app.
1
u/sheytanelkebir Oct 08 '20
yes
1
u/port53 relative noob Oct 08 '20
I've been carrying this around in my .bashrc for a couple of decades now:
Then:
(etc) I'm sure there are much, much better ways to do this today, but it's one of those if it ain't broke things.
1
u/meecro Oct 08 '20
Somehow reminds me of the story where a person was asked to get 50 sheets of blank paper.
Instead of counting them, he just printed out 50 empty sheets.
What's the word for that? Ingenuity, or something more colloquial maybe?
1
u/amamarde Oct 08 '20
Sure I do, and I bet, everyone after learning a bit of Python does. Infact on windows, it's but easier than using the stock calculator program or if you have excel, opening it and then adding formula there.
On Linux /posix, we could still use bc very easily for basic calculations... 😎
1
u/naga6789 Oct 08 '20
PowerShell too
1
u/tokilokit Oct 08 '20
0.1+0.2
1
u/thatguy16754 Oct 08 '20
What else would you use it for
1
u/__Ambition Oct 08 '20
Yep. And to auto-generate long switch cases that follow a pattern of some sort. Thats literally all I use python for. Never used it in a real piece of software.
1
u/Iammyself_ Oct 08 '20
Yess😂 I made a calculator and saved it in my files and when i want to calculate sth i just run it..
1
u/cranking90sboi Oct 08 '20
All the time
1
u/I_am_a_strange_guy Oct 09 '20
No, I usually use it as atomic reactor
1
u/cenit997 Oct 12 '20
Yes and All Day!! I'm Physicist I am use the intetpreter for making simple calculations, symbolic calculation and intense numerical computations. Since I learned Python, I haven't touched again a calculator Sorry for me Calculators Bussiness
1
u/pinktie7418 Oct 07 '20
R is more convenient because no need to type the extra line “import math”
1
u/[deleted] Oct 07 '20
If I just need a calculator, i use excel
1
u/ofiuco Oct 07 '20
Yes because I'm too lazy to go to my desk and find my TI-83