π Step 5: Define get_random_word function
- This function takes a list
wordsas an argument. - The function picks a random position (index) in the list.
- Returns the word from the
wordslist at that position.
π‘ Hint
- Use
randrange(...)orrandint(...)from therandommodule to get random position/number. Store this number in a variable. - To To call a function from a module:
moduleName.functionName(...)βΉοΈ More Information
.randrange(start, stop)or.randrange(stop)generates a number from start or 0 (default) to stop - 1 (start number inclusive, stop number not inclusive).
.randint(a, b)generates a number from a to b (both numbers inclusive).
- Use
len(words)to get the total number on items in the listwords.
- Make sure the index number exists in the
wordslist (index starts at 0 tolen(words)-1).
- To return a word from the list of words, think about indexing/how to access an item from a list.
β Example
list[index]
β Checker
Define get_random_word function
Type or paste your code and run.