Listing 08-02: How not to write a function

##############################################################################
# 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 08/08.02 - How not to write a function.py
##############################################################################
def sum(L):
    total = 0
    x = 0
    while x < 5:
        total += L[x]
        x += 1
    return total
L = [1, 7, 2, 9, 15]
print(sum(L))
print(sum([7, 9, 12, 3, 100, 20, 4]))
Click here to download the file