Skip to content

Task - 1 #769

Open
Open

Description

Activity

  1. HARDIKSINGH07 commented on Jan 18, 2026

    @HARDIKSINGH07

    Basic Calculator Program

    print("Select operation:")
    print("1. Addition")
    print("2. Subtraction")
    print("3. Multiplication")
    print("4. Division")

    choice = input("Enter your choice (1/2/3/4): ")

    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))

    if choice == '1':
    print("Result =", num1 + num2)

    elif choice == '2':
    print("Result =", num1 - num2)

    elif choice == '3':
    print("Result =", num1 * num2)

    elif choice == '4':
    if num2 != 0:
    print("Result =", num1 / num2)
    else:
    print("Error: Cannot divide by zero!")

    else:
    print("Invalid choice")

  2. JokoKusnandi commented on Feb 24, 2026

    @JokoKusnandi

    Your program logic is correct, but the error occurs because of incorrect indentation.
    In Python, indentation is required after if, elif, and else statements.

    ❌ Problems in Your Code

    1. Missing indentation after if and elif
    2. Nested if inside division option also not indented
    3. Python will raise:
    IndentationError: expected an indented block
    
    print("Select operation:")
    print("1. Addition")
    print("2. Subtraction")
    print("3. Multiplication")
    print("4. Division")
    
    choice = input("Enter your choice (1/2/3/4): ")
    
    num1 = float(input("Enter first number: "))
    num2 = float(input("Enter second number: "))
    
    if choice == '1':
        print("Result =", num1 + num2)
    
    elif choice == '2':
        print("Result =", num1 - num2)
    
    elif choice == '3':
        print("Result =", num1 * num2)
    
    elif choice == '4':
        if num2 != 0:
            print("Result =", num1 / num2)
        else:
            print("Error: Cannot divide by zero!")
    
    else:
        print("Invalid choice")
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions