Exercise 02-07:

Using the properties of division and multiplication, try to understand how these results are the same:

0.2 * 6 + 8 * 0.3 + 7 * 0.5 \= (20 * 6 + 8 * 30 + 7 * 50) / 100

Answer:

##############################################################################
# Python From Scratch
# Author: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2025 - LogiKraft 2025
# Site: https://pythonfromscratch.com
# ISBN: 978-85-7522-949-1 (Paperback), 978-85-7522-950-7 (hardcover), 978-85-7522-951-4 (ebook)
#
# File: chapter 02/exercise-02-07.py.py
##############################################################################
# 0.2 * 6 + 8 * 0.3 + 7 * 0.5 = (20 * 6 + 8 * 30 + 7 * 50) / 100
# We can distribute the division on the left side:
# 20 / 100 * 6 + 8 * 30 / 100 + 7 * 50 / 100
# regrouping the common element (100):
# ((20 * 6) + (8 * 30) + 7 * 50) / 100
# All these expressions result in 7.1
Click here to download the file