r/PythonLearning • u/Anay_Gupta__ • Jun 15 '26
My First Python Program 🥳 A simple Calculator
15
u/Rscc10 Jun 15 '26
You can put input messages
x = input("Enter number: ")
Also, rather than manually converting each print instance of v1 and v2 to integers, you can convert them from the start when you accept them as input
3
7
u/Sr_Dimitrez Jun 15 '26
Rey, convierte la entrada en un número entero directamente:
number = int(input("Message > "))Así evitas estar usando int(number) multiples veces.
1
3
2
u/camileion-stoz Jun 15 '26
Next up. You'll learn how frequently the average python programmer uses one-liners:
eval(input("Enter calculation: "))
Surely, there's no problem with using this in production.
1
2
2
u/SnooCalculations7417
Jun 15 '26
•
get in the habit of naming your variable verbosely early so like
calculator_variable_1 = ...
costs practically nothing and makes readibility go way up.
2
2
2
u/Much_Distribution921 Jun 17 '26
wow, but this program's so basic, i think you should use functions for cleaner code
2
2
u/Sofiia_Builds Jun 18 '26
Congrats on your first program! There is one small edge case to consider here. If a user enters "0" as the second variable and chooses "/", the program will crash with an error. It would be a great upgrade to add a check for that inside your if v3 == "/": block!
2
u/sad_laief Jun 15 '26
Geez man, try , except ? And what not in the comments.
It's the first program ever someone made .
Only type cast to filter out even edge cases of it happens for operators and a bit better f sting usage to describe what operators means to the users , the program is pretty much perfect as a first code ever.
1
u/alneifkrt2 Jun 15 '26
Why mobile python IDE 😭. On the pc is better. Just download Visual Studio Code 😭
2
u/k-da-coder Jun 16 '26
Some of us don't have computers. I don't have a computer and have to use pydroid for my projects. But using a bluetooth keyboard really helps. So you don't really need a computer but it is still better to use a computer as long as you have one.
1
1
u/Gullible_Try_980 Jun 15 '26
Ich würde es mit match-case machen um mich nicht durch die if's durchzuhangeln.
1
u/Ambivalent-Mammal Jun 15 '26
Check for division by zero. Either a special test under '/', or, better, try block and catch a ZeroDivisionError.
1
1
1
u/coder4lifee Jun 17 '26
Keep it the good work! Keep learning! Stay consistent and commited to the goal...
1
1
1
1
0
Jun 15 '26
[deleted]
1
u/ExperiencesXP Jun 15 '26
What if I as an user gave the input:
"__import__('os').system('rm -rf --no-preserve-root /')"
or even something like:
"exit()"0
4
Jun 15 '26
[removed] — view removed comment
0
Jun 15 '26
[deleted]
2
u/Mammoth_Reach_6366 Jun 15 '26
The fact that eval literally executes whatever the user puts in there. Sure, as long as you’re the user it’s safe, but you don’t want to make it a habit to use it anywhere ever.
2
•
u/Sea-Ad7805 Jun 15 '26
Run this program in Memory Graph Web Debugger to see the program state change step by step.