Content · Programming · Python

Python Calculate Totals, Differences, Ratios, and Percentages

A total combines several amounts; a difference measures what remains; a ratio compares one quantity with another; and a percentage expresses a fraction out of 100. Ratios require a nonzero denominator. Learn with a.

2 views Published Oct 17, 2026 Updated Oct 18, 2026 Admin

This guide explains Calculate Totals, Differences, Ratios, and Percentages through a focused example and practical reasoning. No prior knowledge of this specific operation is required.

Understanding the Concept


A total combines several amounts; a difference measures what remains; a ratio compares one quantity with another; and a percentage expresses a fraction out of 100. Ratios require a nonzero denominator.

When You Would Use This


A shop wants to know how many items sold, how many remain, and the percent of starting inventory that was purchased.

Step-by-Step Example


starting_stock = 80
items_sold = 28
remaining_stock = starting_stock - items_sold
sold_fraction = items_sold / starting_stock
sold_percentage = sold_fraction * 100
print("Remaining:", remaining_stock)
print(f"Sold: {sold_percentage:.1f}%")

How the Example Works


Subtracting 28 from 80 gives 52 remaining items. 28 / 80 is 0.35, while multiplying by 100 turns it into 35.0%. The percent sign inside the output is ordinary text.

Example Output


Remaining: 52
Sold: 35.0%

Try It Yourself


Start with 120 items and 45 sold; calculate the remaining stock and percent sold.

Common Beginner Mistakes


  • Confusing the ratio 0.35 with the percentage 35%.
  • Dividing by the beginning quantity without checking whether it is zero.
  • Adding quantities with incompatible units and calling the result a total.

Key Takeaways


  • A total combines several amounts; a difference measures what remains; a ratio compares one quantity with another; and a percentage expresses a fraction out of 100.
  • Subtracting 28 from 80 gives 52 remaining items.
  • Avoid this mistake: Confusing the ratio 0.35 with the percentage 35%.
Share this resourceSend this page to someone who may find it useful.