Add Item to List

Beginner

Challenge: Add Item to List

Hello young Python wizard! Today, we have a special challenge for you. Your task is to create a magical function that will allow us to add a new item to a shopping list.

Imagine you have a shopping list with different items like eggs, milk, and bread. Sometimes, you realize you need something extra for the weekend, like cookies 🍪 or chocolate 🍫. Your mission, should you choose to accept it, is to write a function called add_item_to_list that takes in two arguments:

  1. A list representing the shopping list.
  2. A string representing the new item to add.

The function then returns a new list with the new item added to the end of it.

Here's what your code should look like with some examples:

# Example 1 the_list = ['milk', 'bread'] new_item = 'cookies' result = add_item_to_list(the_list, new_item) print(result) # Output: ['milk', 'bread', 'cookies'] # Example 2 the_list = ['apples'] new_item = 'oranges' result = add_item_to_list(the_list, new_item) print(result) # Output: ['apples', 'oranges']

As you can see, the function should simply add the new_item to the end of the_list and return the updated list.

Good luck, and happy coding!

Geek
Inputs

Arg 1:

["milk","bread"]

Arg 2:

"cookies"
Expected Output
["milk", "bread", "cookies"]
Actual Output