diff --git a/HacktoCulator.py b/HacktoCulator.py new file mode 100644 index 00000000..19c41552 --- /dev/null +++ b/HacktoCulator.py @@ -0,0 +1,65 @@ +# --------------------------------------------------------------- +# Simple Calculator Program +# Author: Your Name +# Description: +# A simple command-line calculator that performs +# addition, subtraction, multiplication, and division. +# --------------------------------------------------------------- + +def add(a, b): + """Return the sum of two numbers.""" + return a + b + +def subtract(a, b): + """Return the difference between two numbers.""" + return a - b + +def multiply(a, b): + """Return the product of two numbers.""" + return a * b + +def divide(a, b): + """Return the quotient of two numbers.""" + if b == 0: + return "Error: Division by zero is not allowed." + return a / b + +def calculator(): + """Run the calculator program.""" + print("Welcome to the Python Calculator!") + print("Select an operation:") + print("1. Addition (+)") + print("2. Subtraction (-)") + print("3. Multiplication (*)") + print("4. Division (/)") + print("5. Exit") + + while True: + choice = input("\nEnter your choice (1-5): ") + + if choice == '5': + print("Exiting the calculator. Goodbye!") + break + + if choice in ['1', '2', '3', '4']: + try: + num1 = float(input("Enter first number: ")) + num2 = float(input("Enter second number: ")) + + if choice == '1': + print(f"Result: {add(num1, num2)}") + elif choice == '2': + print(f"Result: {subtract(num1, num2)}") + elif choice == '3': + print(f"Result: {multiply(num1, num2)}") + elif choice == '4': + print(f"Result: {divide(num1, num2)}") + + except ValueError: + print("Invalid input. Please enter numeric values.") + else: + print("Invalid choice. Please select from 1 to 5.") + +# Run the program if executed directly +if __name__ == "__main__": + calculator()