Making Decisions

Recap and Feedback


In this part, you learned to write small interactive Python programs. You worked with input and output, text and numbers, variables, expressions, and decisions. You also practised predicting output, tracing changing values, explaining behavior, and modifying one part of a larger program.

You should now be able to combine these ideas in a complete short program. If an exercise reveals something you do not yet understand, return to the relevant chapter and try its examples again.

The Core Ideas in One Program

Consider this program:

name = input("Name: ").strip()
age = int(input("Age: "))
hours = float(input("Hours studied this week: "))
target_reached = hours >= 5
if age < 18:
group = "under 18"
else:
group = "adult"
print(f"{name}: {group}")
if target_reached:
print("Weekly study target reached.")
else:
print("Weekly study target not reached yet.")

This small program contains many of the ideas from the part:

  • input;
  • strings;
  • numeric conversion;
  • variables;
  • a boolean value;
  • comparisons;
  • two separate decisions;
  • f-string output.

A useful final check is whether you can trace it without running it first.

Parcel Delivery Quote

The following exercise brings together input, numeric calculations, text normalization, decision boundaries, and formatted output.

Calculate a parcel delivery quote

0 / 30 points

Write a program that reads four input lines without visible prompts:

  1. the customer’s name;
  2. the destination: local, national, or international;
  3. the parcel’s weight in kilograms, which may contain a decimal point;
  4. whether express delivery is wanted: yes or no.

Remove surrounding whitespace from the name. Normalize the destination and express answer with .strip().lower(), and convert the weight to a float.

The base price is 2.50 euros per kilogram. Classify the weight as follows:

  • under 2 kg: light;
  • 2 through 10 kg: standard;
  • over 10 kg: heavy.

Add a destination surcharge of 0 euros for local, 4 euros for national, or 12 euros for international. Express delivery adds a separate surcharge of 6 euros. You may assume all inputs are valid.

Print exactly these six lines, replacing the example values with the calculated values:

Name: Ada
Destination: national
Weight class: standard
Base price: 8.75 euros
Delivery: standard
Total price: 12.75 euros

Use express as the delivery value when express delivery was requested and standard otherwise. Format both prices with exactly two digits after the decimal point.

Pay particular attention to weights 2 and 10, which both belong to the standard category. Use a separate decision for the express surcharge because it is independent of the destination and weight classification.

Feedback

Please take a moment to reflect on your work and provide feedback. Your responses help improve the course materials.

Reflection and feedback

0 / 5 points

Consider the following statements and answer them based on your experiences from studying the materials and working on the assignments in this part. When answering the numeric statements, answer them so that value 1 means that you strongly disagree with the statement, and value 7 means that you strongly agree with the statement. Please be as honest as possible when answering. The feedback will be used to improve the course.

Looking Ahead

In Part 2, you will learn how programs can repeat actions and work with several values. Loops, lists, and closer study of strings will let you build programs that do more than handle one set of inputs at a time.