Menu
CoddyTech

Recap: Refactor a Pricing Tool

Lesson 26 of 48 in Coddy's Python for JavaScript Developers course.

challenge icon

Challenge

Beginner

Preserve this pricing behavior while separating the calculations into functions: each record contains nonnegative integer unit price and quantity; its subtotal is their product. An order subtotal is the sum of all line subtotals. Apply a fixed discount once to the order, but never reduce the result below zero. Shipping is 0 when the discounted amount is at least 50, otherwise 5. An empty order costs 0 including shipping. Read nonnegative record count n, then n lines of price quantity, then a nonnegative discount line. Print subtotal discounted shipping total on one line. Define and use functions for line pricing and order calculation; grading accepts any implementation preserving this output contract.

Your code goes in main.py. The locked driver.py starts your program and cannot be edited.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")

All lessons in Python for JavaScript Developers

Practice on your own: Online Python compiler