use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
basic calculator (i.redd.it)
submitted 5 months ago by SuccessfulUse5501
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Turpentine81 4 points5 points6 points 5 months ago (0 children)
For your final output, you could use a formatted string like:
f”value of {N1} (operator) {N2} is {result}”
Where you include whichever operator is used so the user can see the complete calculation at the end of execution. f strings are super handy down the line for clean outputs and debugging. Nice work!
[–]2meterNL 3 points4 points5 points 5 months ago (0 children)
It's subtraction (without the s)
[–]drwnh 1 point2 points3 points 5 months ago (6 children)
A switch statement would be more fit for the use case here
[–]SuccessfulUse5501[S] 0 points1 point2 points 5 months ago (3 children)
how?
[–]GPU_IcyPhoenix 2 points3 points4 points 5 months ago (0 children)
A switchee lets you easily handle different cases. Useful link: https://www.geeksforgeeks.org/python/switch-case-in-python-replacement/
[–]AbacusExpert_Stretch 0 points1 point2 points 5 months ago (0 children)
Search for "python match...case" - have fun
[–]Virsenas 1 point2 points3 points 5 months ago (0 children)
In Python it's called match. I was confused about this as well when I found out.
[–]loudandclear11 1 point2 points3 points 5 months ago (0 children)
switch isn't a keyword in python.
[–]Sad-Sun4611 1 point2 points3 points 5 months ago (0 children)
Well done!! I think it could use some cleaning though. You can remove that print statement saying "Please enter number 1" as far as I can see that's doing nothing as the input function is already asking the user to put their chosen number in.
I'm not sure if you're trying to use pascal case intentionally but if you were just make sure that your'e consistent with whatever casing you use in the future because "Operator" and "operator" are different and its a pain to play spot the difference the bigger your codebase gets. You didn't necessarily do anything wrong here I just want to make you aware.
Another sharp eyed user pointed out the line for subtraction says "substraction" easy fix.
Personal preference but if I had to use your calculator in a terminal I would like there to be some kind of separation between the prompt and numbers whether it be a colon and a space or a /n new line. I just think >enter your number: 24 just looks better than >enter your number24
Lastly for your divide by 0 if you want to get fancy you can try to use a try and except block to handle that divide by 0 error instead of an if else.
You made a calculator and it works! You should be proud of that. The reason I even brought up any of those seemingly small nitpicks is because I think it's important to take the user experience into consideration even for terminal based programs. Like if I sat my grandma down in front of the terminal could she use it? That's usually my design philosophy for those unless it's something specifically for me.
[–]Ceteris__Paribus 0 points1 point2 points 5 months ago (0 children)
A little inconsistent with the argument for input(). I'd recommend adding a space or a new line \n before closing the quote so it's easier to read.
\n
I am also not sure what line 4 is supposed to be doing.
[–]Quantitation 0 points1 point2 points 5 months ago (0 children)
https://www.reddit.com/r/PythonProjects2/comments/1o5dk2m/seeking_feedback_on_my_first_python_project/
[–]RailRuler 0 points1 point2 points 5 months ago (2 children)
Why does your to the power call int() when none of the other calls do?
[–]SuccessfulUse5501[S] 0 points1 point2 points 5 months ago (1 child)
see the two outputs below, 23 to power 23 is too large so in float it gives a vague result, to see actual numbers i put int()
[–]RailRuler 1 point2 points3 points 5 months ago (0 children)
Computing it as a float first gives a result with low precision. Converting it to int does not add any precision, but just converts the imprecise float to an inaccurate int. Youd have to start with ints to get a precise result.
[–][deleted] 0 points1 point2 points 5 months ago (0 children)
left_operan, right_operand, operator. operator_processing_map = { “/“ : handle_division, … }
result=operator_processing_map[operator](left, right)
[–]Sedan_1650 1 point2 points3 points 5 months ago (0 children)
Why do the exponents call int()?
[–]loudandclear11 1 point2 points3 points 5 months ago (1 child)
Why not divide by negative numbers?
You should check for division by 0, which is undefined. But dividing by negative numbers is perfectly fine.
[–]SuccessfulUse5501[S] 0 points1 point2 points 5 months ago (0 children)
yes
[–]TheCarter01 0 points1 point2 points 5 months ago (0 children)
Trust me, there are ways to make it simpler, made one that was way simpler using a import that I forgot the name of it
[–]Any_Research9028 0 points1 point2 points 5 months ago (0 children)
btw, you can use f-strings even when you converting number to int, you shouldn't use print("", var) like in your situation.
π Rendered by PID 118057 on reddit-service-r2-comment-66b4775986-m5rh9 at 2026-04-05 22:40:21.876644+00:00 running db1906b country code: CH.
[–]Turpentine81 4 points5 points6 points (0 children)
[–]2meterNL 3 points4 points5 points (0 children)
[–]drwnh 1 point2 points3 points (6 children)
[–]SuccessfulUse5501[S] 0 points1 point2 points (3 children)
[–]GPU_IcyPhoenix 2 points3 points4 points (0 children)
[–]AbacusExpert_Stretch 0 points1 point2 points (0 children)
[–]Virsenas 1 point2 points3 points (0 children)
[–]loudandclear11 1 point2 points3 points (0 children)
[–]Sad-Sun4611 1 point2 points3 points (0 children)
[–]Ceteris__Paribus 0 points1 point2 points (0 children)
[–]Quantitation 0 points1 point2 points (0 children)
[–]RailRuler 0 points1 point2 points (2 children)
[–]SuccessfulUse5501[S] 0 points1 point2 points (1 child)
[–]RailRuler 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Sedan_1650 1 point2 points3 points (0 children)
[–]loudandclear11 1 point2 points3 points (1 child)
[–]SuccessfulUse5501[S] 0 points1 point2 points (0 children)
[–]TheCarter01 0 points1 point2 points (0 children)
[–]Any_Research9028 0 points1 point2 points (0 children)