DEV Community

Cover image for Squared Numbers Function
Scott Gordon
Scott Gordon

Posted on

2 1

Squared Numbers Function

# squared_number_function.py
#   This program uses a function to square each entry in a numbers list.
# by: Scott Gordon

def main():

    numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    squared_numbers = []

    def square_each(numbers):
        """This program uses a function to square each entry in a numbers list."""
        for number in numbers:
            squared_numbers.append(number ** 2)
        return squared_numbers

    print(square_each(numbers))


main()

Enter fullscreen mode Exit fullscreen mode

Photo by Volkan Olmez on Unsplash

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs