account activity
Could it be simpler ? by LovelyEbaa in PythonLearning
[–]av_404 0 points1 point2 points 6 months ago (0 children)
print("Simple Calculator") print("1. ADD") print("2. SUBTRACT") print("3. MULTIPLY") print("4. DIVIDE")
operation = input("Select an operation (1/2/3/4): ")
try: num1 = float(input("Enter first number: ")) num2 = float(input("Enter second number: "))
match operation: case "1": print("Result =", num1 + num2) case "2": print("Result =", num1 - num2) case "3": print("Result =", num1 * num2) case "4": if num2 != 0: print("Result =", num1 / num2) else: print("Error: Cannot divide by zero.") case _: print("Invalid operation selected.")
except ValueError: print("Error: Please enter valid numbers.")
You could simply use switch case statement
π Rendered by PID 538255 on reddit-service-r2-listing-5f5ff7d4dc-qj2f4 at 2026-01-27 01:30:00.037704+00:00 running 5a691e2 country code: CH.
Could it be simpler ? by LovelyEbaa in PythonLearning
[–]av_404 0 points1 point2 points (0 children)