Addition, Subtraction, Multiplication, Division, Modulus Challenges

Code Runner Challenge

Challenge Collection - Fixed Code

View IPYNB Source
%%python

# CODE_RUNNER: Challenge Collection - Fixed Code

# Fixed Addition: Converted string "5" to integer 5
total = 10 + int("5")  # Or total = 10 + 5
print(total)  # Output: 15

# Fixed Subtraction: Corrected variable name from resul to result
result = 10 - 5
print(result)  # Output: 5

# Fixed Multiplication: Replaced 'x' with Python's multiplication operator '*'
product = 10 * 5
print(product)  # Output: 50

# Fixed Division: Changed divisor from 0 to 5 to avoid ZeroDivisionError
quotient = 10 / 5
print(quotient)  # Output: 2

# Fixed Modulus: Used % operator to find remainder of 10 divided by 3
remainder = 10 % 3
print(remainder)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Homework Hack 1

Code Runner Challenge

Homework Hack 1

View IPYNB Source
%%python

# CODE_RUNNER: Homework Hack 1

# Game Boss Level Detector Challenge
player_level = 15

# Use the modulo operator (%) to check if player_level is divisible by 5
is_boss_level = player_level % 5

if is_boss_level == 0:
    print("⚠️ WARNING: Level " + str(player_level) + " is a Boss Level! Prepare")
else:
    print("Level " + str(player_level) + " cleared! Regular enemies ahead.")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Homework Hack 2

Code Runner Challenge

Homework Hack 2

View IPYNB Source
%%python

# CODE_RUNNER: Homework Hack 2

# Game Score & Bonus Tracker

# 1. Base Variables
base_score = 50
multiplier = 2
bonus_points = 15

# 2. Calculate total score following PEMDAS (Multiplication happens before addition)
#    (50 * 2) + 15 = 100 + 15 = 115
total_score = base_score * multiplier + bonus_points
print("Total Score: " + str(total_score))

# 3. Modulo check: Award an extra life for every 25 points
remainder = total_score % 25

if remainder == 0:
    print("🎉 Bonus! You earned an extra life!")
else:
    points_needed = 25 - remainder
    print("Points needed for next extra life: " + str(points_needed))
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...