Input: ['apple', 'banana', 'cherry']
Output: 'banana' # Output may vary
The random module contains a function choice() that selects a random item from a list.
import random
# Define the function
def select_random_item(lst):
return random.choice(lst)
# Test the function
print(select_random_item([1, 2, 3, 4, 5])) # Output may vary
print(select_random_item(['apple', 'banana', 'cherry'])) # Output may vary
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.