Get startedGet started for free

Write a pure function

It's time to write your first pure function! You've been working with some data that contains price information for all of the items in your company's inventory. What you didn't realize when you started, however, was that all of the price information is in cents when you expected it to be in dollars. You are going to need to write a function to convert all of the prices from cents to dollars by dividing the values by 100. Make sure you don't create any side effects or rely on any values outside of the function!

This exercise is part of the course

Programming Paradigm Concepts

View Course

Exercise instructions

  • Complete the code below to write a pure function that takes a list (input_list) as input, divides each item in the list by 100, and then returns the new list.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

def square_list(input_list):
    new_list = []
    # Loop through each item in the input list
    for item in ____:
        # Divide each item by 100
        new_item = ____ / 100
        # Append the new item to the new list
        new_list.append(____)
    # Return the new list
    return ____
Edit and Run Code