Complete the code to create a simple generative AI model that outputs random text.
import random words = ['hello', 'world', 'AI', 'generative', 'model'] output = random.[1](words) print(output)
The random.choice() function picks one random item from a list, which fits generating a random word.
Complete the code to define a function that generates a sentence by joining words.
def generate_sentence(words): return ' '.[1](words) sentence = generate_sentence(['Generative', 'AI', 'creates', 'content']) print(sentence)
The join() method combines a list of words into a single string separated by spaces.
Fix the error in the code that generates a random sequence of numbers for a generative model.
import random sequence = [random.randint(0, 9) for _ in range([1])] print(sequence)
The range() function needs an integer. Using 10 correctly sets the length of the sequence.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['AI', 'model', 'generate', 'text'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary maps each word to its length using len(word), and filters words with length greater than (>) 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 4.
words = ['data', 'science', 'AI', 'modeling'] result = { [1]: [2] for w in words if len(w) [3] 4 } print(result)
The dictionary maps uppercase words (w.upper()) to their lengths (len(w)) only if the length is greater than (>) 4.