Menu
CoddyTech

Branch Priority

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

Preserve rule priority when translating conditional logic.

C# reference excerpt

Executable statements use C# top-level program style; type-only examples are declarations. System names assume the usual using System directive.

int score = 72;
string label = score >= 60 ? "pass" : "retry";
Console.WriteLine(label);

Python

score = 72
label = "pass" if score >= 60 else "retry"
print(label)

What changes

Use if, elif, else for ordered branches. Only the first matching branch runs. Python conditional expressions put the result before the condition, unlike the C# condition ? yes : no order. A comparison such as 0 <= score <= 100 is a Python chained comparison; do not copy that syntax into C#.

Transfer mistake

Separate if statements can all execute; use elif when rules have priority. For the task, the free-shipping threshold must win over membership.

Your task

Read a nonnegative order total in cents and then yes or no for membership. Shipping costs 0 if total is at least 5000; otherwise it costs 200 for yes and 500 for no. Output the shipping amount, then free for a zero shipping amount or paid otherwise. Evaluate the high-total rule before membership.

challenge icon

Challenge

Beginner

Read a nonnegative order total in cents and then yes or no for membership. Shipping costs 0 if total is at least 5000; otherwise it costs 200 for yes and 500 for no. Output the shipping amount, then free for a zero shipping amount or paid otherwise. Evaluate the high-total rule before membership.

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__")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Python for C# Developers

Practice on your own: Online Python compiler