LoslegenKostenlos loslegen

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!

Diese Übung ist Teil des Kurses

Programming Paradigm Concepts

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

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 ____
Code bearbeiten und ausführen