Feedback

Chat Icon

Learn Git in a Day

Everything you need, nothing you don't

Keep Your Branch in Sync
60%

Watch It Happen

Let's set up the scenario. First, make sure you're on main and up to date:

git switch main
git pull

Now create a branch and add an absolute value function:

git switch -c feature/absolute

New content:

cat << 'EOF' > calculator.py
# calculator.py - A simple calculator
# Hosted on GitLab

import math

def add(a, b):
    """Add two numbers and return the result."""
    return a + b

def subtract(a, b):
    """Subtract b from a and return the result."""
    return a - b

def multiply(a, b):
    """Multiply two numbers and return the result."""
    return a * b

def divide(a, b):
    """Divide a by b and return the result."""
    if b == 0:
        return "Error: Cannot divide by zero"
    return a / b

def power(a, b):
    """Raise a to the power of b and return the result."""
    return a ** b

def modulo(a, b):
    """Return the remainder of a divided by b."""
    if b == 0:
        return "Error: Cannot divide by zero"
    return a % b

def square_root(a):
    """Return the square root of a."""
    if a < 0:
        return "Error: Cannot compute square root of negative number"
    return math.sqrt(a)

def floor_divide(a, b):
    """Divide a by b and return the integer part (floor division)."""
    if b == 0:
        return "Error: Cannot divide by zero"

Learn Git in a Day

Everything you need, nothing you don't

Enroll now to unlock all content and receive all future updates for free.

Unlock now  $9.99$7.49

Hurry! This limited time offer ends in:

To redeem this offer, copy the coupon code below and apply it at checkout:

Learn More