Work on Two Things at Once
36%
Build a Feature in Isolation
Make sure you're on the feature/power branch:
git switch feature/power
Let's add the power function on our feature/power branch:
cat << 'EOF' > calculator.py
# calculator.py - A simple calculator
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
# Try it out
result_add = add(5, 3)
result_sub = subtract(10, 4)
result_mul = multiply(6, 7)
result_div = divide(10, 2)
result_pow = power(2, 8)
print(f"5 + 3 = {result_add}")
print(f"10 - 4 = {result_sub}")
print(f"6 * 7 = {result_mul}")
print(f"10 / 2 = {result_div}")
print(f"2 ^ 8 = {result_pow}")
EOF
Stage and commit:
git add calculator.py
git commit -m "Add power function"
Now let's see what happens when we switch back to main:
git switch main
python3 calculator.py
Learn Git in a Day
Everything you need, nothing you don'tEnroll now to unlock all content and receive all future updates for free.
Unlock now $9.99$7.49Learn More
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
