0
0
Prompt Engineering / GenAIml~10 mins

What Generative AI actually is in Prompt Engineering / GenAI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple generative AI model that outputs random text.

Prompt Engineering / GenAI
import random
words = ['hello', 'world', 'AI', 'generative', 'model']
output = random.[1](words)
print(output)
Drag options to blanks, or click blank then click option'
Asample
Bshuffle
Cchoice
Drandint
Attempts:
3 left
💡 Hint
Common Mistakes
Using random.shuffle() changes the list order but returns None.
random.sample() returns multiple items, not one.
2fill in blank
medium

Complete the code to define a function that generates a sentence by joining words.

Prompt Engineering / GenAI
def generate_sentence(words):
    return ' '.[1](words)

sentence = generate_sentence(['Generative', 'AI', 'creates', 'content'])
print(sentence)
Drag options to blanks, or click blank then click option'
Ajoin
Bsplit
Creplace
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using split() breaks strings into lists.
append() adds items to a list, not strings.
3fill in blank
hard

Fix the error in the code that generates a random sequence of numbers for a generative model.

Prompt Engineering / GenAI
import random
sequence = [random.randint(0, 9) for _ in range([1])]
print(sequence)
Drag options to blanks, or click blank then click option'
Arandom
B10
Crange
D'ten'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like 'ten' causes an error.
Using range or random as a number is invalid.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Prompt Engineering / GenAI
words = ['AI', 'model', 'generate', 'text']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for values.
Using < instead of > for filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 4.

Prompt Engineering / GenAI
words = ['data', 'science', 'AI', 'modeling']
result = { [1]: [2] for w in words if len(w) [3] 4 }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using w.lower() instead of w.upper().
Using < instead of > for filtering.