Menu
CoddyTech

Recap: Port a Receipt

Lesson 6 of 48 in Coddy's Python for C# Developers course.

challenge icon

Challenge

Beginner

Input consists of an item name, a nonnegative quantity, and a nonnegative unit price in cents on three lines. Multiply quantity by unit price. For quantities above 3, subtract 10 cents; such test cases have a pre-discount total of at least 10. Output the name, then the final integer total. Add a third line bulk only when discounted. Preserve spaces in the item name.

C# transfer checkpoint

Port the arithmetic and branch behavior while replacing C# braces with Python indentation.

C# reference excerpt: executable statements assume using System; type-only excerpts illustrate the declared contract.

int total = 2 * 150;
if (2 > 3) total -= 10;

Python pattern

total = 2 * 150
if 2 > 3:
    total -= 10

Editable implementation files: main.py. The locked driver.py is the supplied launcher or input/output harness and must remain unchanged.

Use the supplied input contract without prompts. Print only the required lines, each ending in a newline.

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 C# Developers

Practice on your own: Online Python compiler