- ๐ 20 points available
- โ๏ธ Last updated on 9/10/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: Netflixโs Debt-to-Equity Ratio ๐ตยถ
๐ Taskยถ
The debt-to-equity ratio shows the proportion of debt and equity a company uses to finance its assets.
It is calculated by dividing total debt by total equity.
Your goal is to calculate Netflixโs debt_to_equity_ratio using the variables netflix_total_debt and netflix_total_equity. Store the result to a new variable named debt_to_equity_ratio.
๐ก Hintยถ
For example, 25 / 10 evaluates to 2.5.
netflix_total_debt = 15582804
netflix_total_equity = 24743567
# YOUR CODE BEGINS
# YOUR CODE ENDS
print(f"Netflix's debt-to-equity ratio is {round(debt_to_equity_ratio, 2)}")๐งญ 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-debt-to-equity-ratio'
_points = 4
tc.assertAlmostEqual(debt_to_equity_ratio, 0.6297719322359626)๐ฏ Challenge 2: Movie vs. TV ๐ฌ๐บยถ
๐ Taskยถ
p_moviecontains the probability (0โ1) that a person prefers movies.p_tvcontains the probability (0-1) that a person prefers TV shows.- If
p_movieis greater thanp_tv, setresultto"Movie". - Otherwise, set
resultto"TV".
p_movie = 0.47
p_tv = 0.53
result = None
# YOUR CODE BEGINS
# YOUR CODE ENDS
print(result)๐งญ 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 = 'movie-vs-tv'
_points = 4
tc.assertEqual(result, "TV")๐ฏ Challenge 3: Shipping Fee ๐ยถ
๐ Taskยถ
The amount variable contains the total order amount in dollars.
In this exercise, amount will be randomly generated each time you run the code (between 1 and 150).
Your task is to set a variable named shipping_fee to one of the following values based on amount:
"Free Shipping"ifamount >= 100"Discounted Shipping"if50 <= amount < 100"Standard Shipping"ifamount < 50
๐ Exampleยถ
If amount = 75, then:
shipping_feeis"Discounted Shipping".
๐ Rulesยถ
- Use an
if/elif/elsestructure to complete this task. - Do not hardcode the result; your code should work for any randomized
amountvalue.
import random
amount = random.randint(1, 150) # purchase amount between $1 and $150
# YOUR CODE BEGINS
# YOUR CODE ENDS
print(f"Order amount: {amount}")
print(f"Shipping fee: {shipping_fee}")๐งญ 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 = 'shipping-fee'
_points = 6
shipping_fee_SOL = (
"Free Shipping" if amount >= 100
else "Discounted Shipping" if amount >= 50
else "Standard Shipping"
)
tc.assertEqual(shipping_fee, shipping_fee_SOL)๐ฏ Challenge 4: Scholarship Eligibility ๐ยถ
๐ Taskยถ
The following variables are given:
gpaโ a studentโs grade point average (0.0โ4.0)creditsโ the total number of credits the student has earnedvolunteer_hoursโ the number of volunteer hours completed
Your task is to determine eligibility for two scholarships:
Merit Scholarship
- Eligible if
gpa >= 3.5andcredits >= 30
- Eligible if
Community Scholarship
- Eligible if
gpa >= 3.0orvolunteer_hours >= 100
- Eligible if
Set two Boolean variables:
merit_eligibleโTrueif the student qualifies for the Merit Scholarship, otherwiseFalsecommunity_eligibleโTrueif the student qualifies for the Community Scholarship, otherwiseFalse
๐ Exampleยถ
gpa = 3.6
credits = 28
volunteer_hours = 120merit_eligibleisFalse(credits < 30)community_eligibleisTrue(volunteer hours >= 100)
๐ Rulesยถ
- Use logical operators (
and,or) to complete this task. - Do not hardcode the results; your code should work for any values of
gpa,credits, andvolunteer_hours.
import random
gpa = round(random.uniform(0.0, 4.0), 2) # GPA between 0.00 and 4.00
credits = random.randint(0, 60) # credits between 0 and 60
volunteer_hours = random.randint(0, 200) # volunteer hours between 0 and 200
# YOUR CODE BEGINS
# YOUR CODE ENDS
print(f"GPA: {gpa}")
print(f"Credits: {credits}")
print(f"Volunteer Hours: {volunteer_hours}")
print(f"Merit Scholarship Eligible? {merit_eligible}")
print(f"Community Scholarship Eligible? {community_eligible}")๐งญ 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 = "scholarship-eligibility"
_points = 6
merit_eligible_SOL = True and (not False) and gpa >= 3.5 and credits >= 30
community_eligible_SOL = False or (not True) or gpa >= 3.0 or volunteer_hours >= 100
tc.assertEqual(merit_eligible, merit_eligible_SOL)
tc.assertEqual(community_eligible, community_eligible_SOL)