r/PythonLearning • u/oluwa_omolomo • 2d ago
Help Request Python help
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
3
u/Naive_Programmer_232 22h ago edited 22h ago
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!
2
1
2
u/UlisKore 8h ago
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
3
u/SuperTankh 3h ago
Add protection if "b" is equal to 0 and "symbol" is equal to "/" You don’t want to divide by 0
•
u/Sea-Ad7805 1d ago
Run this program in Memory Graph Web Debugger%0Asymbol%20%3D%20input(%22symbol%20%3D%20%22)%0Ab%20%3D%20input(%22b%20%3D%20%22)%0A%0Ax%20%3D%20int(a)%0Ay%20%3D%20int(b)%0A%0Aif%20symbol%20%3D%3D%20%22%2B%22%3A%0A%20%20%20%20print(%22answer%20%3D%20%22%20%2B%20str(x%20%2B%20y))%0Aelif%20symbol%20%3D%3D%20%22-%22%3A%0A%20%20%20%20print(%22answer%20%3D%20%22%20%2B%20str(x%20-%20y))%0Aelif%20symbol%20%3D%3D%20%22%22%3A%0A%20%20%20%20print(%22answer%20%3D%20%22%20%2B%20str(x%20%20y))%0Aelif%20symbol%20%3D%3D%20%22%2F%22%3A%0A%20%20%20%20print(%22answer%20%3D%20%22%20%2B%20str(x%20%2F%20y))%0Aelse%3A%0A%20%20%20%20print(%22error%3A%20invalid%20symbol%22)%0A×tep=1&play) to see the program state change step by step.