Skip to main content

Section 9.21 Write Code Questions Orig

Activity 9.21.1.

Write a function item_lister that takes in a list of at least three values, items, as a parameter. Set the first value to โ€œFirst itemโ€, set the second value to the original first value, and set the third value to its current value plus one (rounded to two decimals). (Note: the third value of items will only be numerical.) Then, return the modified list. For example, itemLister([2,4,6.222,8]) would return ['First item', 2, 7.22, 8].

Activity 9.21.2.

Create a function item_lister that takes in a list of at least three values, items, as a parameter. Set the first value to โ€œFirst itemโ€, set the second value to the original first value, and set the third value to its current value plus one (rounded to two decimals). (Note: the third value of items will only be numerical.) Then, return the modified list. For example, itemLister([2,4,6.222,8]) would return ['First item', 2, 7.22, 8].

Activity 9.21.3.

Write the function change_index3 that takes in one parameter, lst, and assigns the value at index 3 of lst to โ€˜200โ€™ and then returns lst. For example, change_index3(['hi', 'goodbye', 'python', '106', '506']) would return ['hi', 'goodbye', 'python', '200', '506'] and change_index3([1, 2, 0, -5, 4]) would return [1, 2, 0, '200', 4].

Activity 9.21.4.

Create the function change_index3 that takes in one parameter, lst, and assigns the value at index 3 of lst to โ€˜200โ€™ and then returns lst. For example, change_index3(['hi', 'goodbye', 'python', '106', '506']) would return ['hi', 'goodbye', 'python', '200', '506'] and change_index3([1, 2, 0, -5, 4]) would return [1, 2, 0, '200', 4].

Activity 9.21.5.

Write a function countWords that takes in a list, lst, as a parameter, and returns the amount of words that have a length of 5. For example, countWords(['hello', 'hi', 'good morning', 'three', 'kitty']) should return 3.

Activity 9.21.6.

Create a function countWords that takes in a list, lst, as a parameter, and returns the amount of words that have a length of 5. For example, countWords(['hello', 'hi', 'good morning', 'three', 'kitty'] should return 3.

Activity 9.21.7.

Write a function reverse that takes in one parameter, lst, and returns the reverse of a passed list. For example, reverse([1,2,3]) should return [3, 2, 1].

Activity 9.21.8.

Create a function reverse that takes in one parameter, lst, and returns the reverse of a passed list. For example, reverse([1,2,3]) should return [3, 2, 1].

Activity 9.21.9.

Write a function sort_by_length that takes in one parameter, a list of strings, lst, and returns the list sorted by the length of the strings. For example, sort_by_length(["hello", "hi", "hey", "greetings"]) would return ['hi', 'hey', 'hello', 'greetings'].

Activity 9.21.10.

Create a function reverse that takes in one parameter, lst, and returns the reverse of a passed list. For example, reverse([1,2,3]) should return [3, 2, 1].
You have attempted of activities on this page.