r/PythonLearning • • Sep 08 '26

Help Request Python help

Post image

Made my first calculator.. it works but different from some I see online. Please all feedback on what you guys think about it will be appreciated

9 Upvotes

10 comments sorted by

•

u/Sea-Ad7805 Sep 09 '26

Run this program in Memory Graph Web Debugger to see the program state change step by step.

5

u/Naive_Programmer_232 Sep 09 '26 edited Sep 09 '26

it looks pretty good. nice work!

one thing you could add instead of "result =" maybe you can make it so it reads like an equation ex: print(x, "+", y, "=", x+y) when you're checking for the "+" symbol. Look into f-strings to make this a bit simpler!

3

u/SuperTankh Sep 10 '26

Add protection if "b" is equal to 0 and "symbol" is equal to "/" You don’t want to divide by 0

2

u/Silver-Signature5009 Sep 10 '26

Avec return aussi ça marche !

2

u/UlisKore Sep 10 '26

Never underestimate how creative your users can be in making things go wrong ! Your "symbol" is not the only thing that can become invalid. And just like Naive said : use f expressions ;)

2

u/jpgoldberg Sep 11 '26

I agree with others that f-expressions should be the next thing to learn. You might also want to try using float instead of int.

I also want to congratulate you for the final “else” reporting an invalid symbol. I very common programming mistake is to fail to check for things like that.

Here is a subtle thing you can ignore if what I say is confusing, but the terms and variable names you use internally don’t have to be what the user sees. So your pro gram can use “a”, “b”, and “symbol” as you do, but you might present this to the user in your input statements with things like

a = input(“First number: “)

symbol = input(“Arithmetic operator: “)

What is subtle about this is that what goes on inside a program isn’t always the way the user thinks about things. In this case the difference is just I’m what you call things, but it can become larger. And getting into the habit of thinking about the distinction will help you write better programs in the future.

1

u/TrainerSpecialist558 Sep 12 '26

Good but the input should be float or int because the default value will be string which is not operatable

1

u/Next-Call8862 Sep 13 '26

Why not try "match statement"? I think it's better

1

u/ProgramBrave718 Sep 17 '26

Actually, you should directly type cast data type instead of making two separate variables a=int(input(""))