- 🏆 20 points available
- ✏️ Last updated on 9/7/2025
▶️ First, run the code cell below to import unittest, the module used for the 🧭 Check Your Work boxes and the autograder.
# DO NOT MODIFY THE CODE IN THIS CELL
import unittest
tc = unittest.TestCase()🎯 Challenge 1: Find the Smaller Number¶
👇 Tasks¶
Create a function named find_smaller that takes two numbers as input (parameters).
- The function should return the smaller of the two values.
- If both values are equal, return either one.
- Do not use Python’s built-in min()function.
💡 Expected Output¶
7
-10
0# YOUR CODE BEGINS
# YOUR CODE ENDS
print(find_smaller(9, 7))
print(find_smaller(-10, -5))
print(find_smaller(0, 0))🧭 Check Your Work¶
Run the code cell below to test your solution.
- ✔️ If the code cell runs without errors, you’re good to move on.
- ❌ If the code cell produces an error, review your code and fix any mistakes.
_test_case = 'find-smaller'
_points = 3
tc.assertEqual(find_smaller(5, 5), 5)
tc.assertEqual(find_smaller(8, 5), 5)
tc.assertEqual(find_smaller(-7, -2), -7)🎯 Challenge 2: Find the Largest Number in a List¶
👇 Tasks¶
Create a function named find_largest that takes one parameter of type list.
- The list will only contain numbers.
- You can assume the list will always have at least one element.
- The find_largestfunction should return the largest value in the list.
⚔️ Special Requirement¶
Do not use Python’s built-in max() function.
🧭 Tips¶
- Create a variable named largestinside the function. Initialize it with the first element of the list.
- Use a forloop to iterate through the list. For each value, updatelargestifvalue > largest.
🔑 Expected Output¶
8
5
10# YOUR CODE BEGINS
# YOUR CODE ENDS
print(find_largest([5, 3, 8]))
print(find_largest([5, -7, -4]))
print(find_largest([9, 5, 4, 1, 3, 7, 0, 10]))🧭 Check Your Work¶
Run the code cell below to test your solution.
- ✔️ If the code cell runs without errors, you’re good to move on.
- ❌ If the code cell produces an error, review your code and fix any mistakes.
_test_case = 'find-the-largest-number-in-a-list'
_points = 4
tc_input_lists = [
    [4, 7, 3],
    [-1, -12, -3, -4, -5],
    [0, 0]
]
for l in tc_input_lists:
    tc.assertEqual(find_largest(l), max(l), f'find_largest({l}) should print out {max(l)}, not {find_largest(l)}.')🎯 Challenge 3: Multiples of Four Checker¶
👇 Tasks¶
Create a function named is_multiple_of_four that takes one numeric parameter.
- The function should return Trueif the input is a multiple of4.
- Otherwise, it should return False.
💡 Expected Output¶
False
True
False
True# YOUR CODE BEGINS
# YOUR CODE ENDS
print(is_multiple_of_four(3))
print(is_multiple_of_four(8))
print(is_multiple_of_four(-10))
print(is_multiple_of_four(-4))🧭 Check Your Work¶
Run the code cell below to test your solution.
- ✔️ If the code cell runs without errors, you’re good to move on.
- ❌ If the code cell produces an error, review your code and fix any mistakes.
_test_case = 'multiples-of-four-checker'
_points = 3
tc.assertEqual(is_multiple_of_four(7), False)
tc.assertEqual(is_multiple_of_four(-16), True)
tc.assertEqual(is_multiple_of_four(4), True)🎯 Challenge 4: Calculate Revenue from an Order¶
👇 Tasks¶
- Create a function named get_revenuethat takes one parameter of typedict(dictionary).
- The input dictionary will contain details about a product order with three keys: product,quantity, andunit_price.
- The get_revenuefunction should return the product ofquantityandunit_price.
🔑 Expected Output¶
40.0
45.0
149.9o1 = {"product": "Tape", "quantity": 20, "unit_price": 2.0}
o2 = {"product": "Ruler", "quantity": 30, "unit_price": 1.5}
o3 = {"product": "Flash Cards", "quantity": 10, "unit_price": 14.99}
# YOUR CODE BEGINS
# YOUR CODE ENDS
print(get_revenue(o1))
print(get_revenue(o2))
print(get_revenue(o3))🧭 Check Your Work¶
Run the code cell below to test your solution.
- ✔️ If the code cell runs without errors, you’re good to move on.
- ❌ If the code cell produces an error, review your code and fix any mistakes.
_test_case = 'calculate-revenue-from-order'
_points = 5
tc.assertEqual(get_revenue({"quantity": 15, "unit_price": 3.0}), 45.0)
tc.assertEqual(get_revenue({"quantity": 0, "unit_price": 45.0}), 0)🎯 Challenge 5: Convert USD to INR with a Fee¶
👇 Tasks¶
You are working as a bank teller responsible for converting United States Dollars (USD $) to Indian Rupees (INR ₹).
Create a function named usd_to_inr_with_fee that takes the following three parameters (in this order):
- amount: The amount in USD (can be- intor- float).
- rate: The conversion rate between USD and INR. For example, a rate of- 90means that 100 USD converts to 9000 INR (assuming the fee is already paid).
- fee: A fixed currency conversion fee in USD (applies regardless of the amount).
The function should:
- First subtract the feefromamount.
- Multiply the result by the rate.
- Return the converted amount in INR.
Mathematical formula:
🔑 Expected Output¶
8000
10620
19700# YOUR CODE BEGINS
# YOUR CODE ENDS
print(usd_to_inr_with_fee(105, 80, 5))  # amount = 105,
                                        # rate = 80
                                        # fee = 5
print(usd_to_inr_with_fee(120, 90, 2))
print(usd_to_inr_with_fee(200, 100, 3))🧭 Check Your Work¶
Run the code cell below to test your solution.
- ✔️ If the code cell runs without errors, you’re good to move on.
- ❌ If the code cell produces an error, review your code and fix any mistakes.
_test_case = 'convert-usd-to-inr-with-a-fee'
_points = 5
tc.assertAlmostEqual(usd_to_inr_with_fee(5550, 70, 4), 388220)
tc.assertAlmostEqual(usd_to_inr_with_fee(2255, 71, 15), 159040)
tc.assertAlmostEqual(usd_to_inr_with_fee(2421, 72, 10), 173592)