Bird
Raised Fist0
Prompt Engineering / GenAIml~10 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main purpose of Generative AI?
easy
A. To store large amounts of data efficiently
B. To delete irrelevant information from datasets
C. To only classify existing data into categories
D. To create new content by learning from examples

Solution

  1. Step 1: Understand the role of Generative AI

    Generative AI learns patterns from data and creates new content based on those patterns.
  2. Step 2: Compare options with the definition

    Only To create new content by learning from examples describes creating new content by learning from examples, which matches the main purpose.
  3. Final Answer:

    To create new content by learning from examples -> Option D
  4. Quick Check:

    Generative AI = create new content [OK]
Hint: Generative AI makes new stuff from learned data [OK]
Common Mistakes:
  • Confusing Generative AI with data storage
  • Thinking it only classifies data
  • Believing it deletes data
2. Which of the following is the correct way to describe Generative AI in simple code terms?
easy
A. Train a model, then generate new outputs
B. Only collect data without processing
C. Manually write all new content
D. Delete old models before training

Solution

  1. Step 1: Identify the typical workflow of Generative AI

    Generative AI involves training a model on data and then using it to create new outputs.
  2. Step 2: Match options to this workflow

    Train a model, then generate new outputs correctly states this process, while others describe unrelated or incorrect actions.
  3. Final Answer:

    Train a model, then generate new outputs -> Option A
  4. Quick Check:

    Train then generate = correct process [OK]
Hint: Generative AI = train model + create new data [OK]
Common Mistakes:
  • Thinking Generative AI only collects data
  • Assuming manual content creation is AI
  • Confusing training with deleting models
3. Consider this Python-like pseudocode for a simple Generative AI process:
model = train(data)
new_content = model.generate()

What will new_content most likely contain?
medium
A. A new example similar to the training data
B. The original training data unchanged
C. An error message because generate() is undefined
D. An empty output with no content

Solution

  1. Step 1: Understand the code steps

    The code trains a model on data, then calls generate() to create new content.
  2. Step 2: Predict the output of generate()

    Generate() produces new content similar to what the model learned, not the original data or errors.
  3. Final Answer:

    A new example similar to the training data -> Option A
  4. Quick Check:

    generate() = new similar content [OK]
Hint: generate() creates new data like training examples [OK]
Common Mistakes:
  • Thinking generate() returns original data
  • Assuming generate() causes an error
  • Expecting empty output
4. The following code is intended to train a Generative AI model and generate new content:
model = train(data)
new_content = model.generate(data)

What is the likely problem here?
medium
A. model should be a list, not a model object
B. train() should not take data as input
C. generate() should not take data as input after training
D. new_content should be assigned before training

Solution

  1. Step 1: Review typical usage of generate()

    After training, generate() usually creates new content without needing input data again.
  2. Step 2: Identify misuse in code

    Passing data to generate() is incorrect; it should generate based on learned patterns alone.
  3. Final Answer:

    generate() should not take data as input after training -> Option C
  4. Quick Check:

    generate() no input needed [OK]
Hint: generate() uses learned model, no extra data input [OK]
Common Mistakes:
  • Thinking train() shouldn't take data
  • Confusing model type
  • Assigning new_content before training
5. You want to create a Generative AI that writes short poems. Which steps best describe the process?
hard
A. Write poems manually, then use AI to classify them
B. Collect poem examples, train model on them, generate new poems
C. Train model on random text, then delete training data
D. Generate poems first, then collect examples to train

Solution

  1. Step 1: Understand the goal of Generative AI for poems

    The AI needs to learn from existing poems to create new ones.
  2. Step 2: Identify the correct sequence of actions

    Collecting examples, training the model, then generating new poems is the correct order.
  3. Final Answer:

    Collect poem examples, train model on them, generate new poems -> Option B
  4. Quick Check:

    Learn from examples, then create new [OK]
Hint: Train on examples first, then generate new content [OK]
Common Mistakes:
  • Trying to generate before training
  • Confusing classification with generation
  • Deleting training data too early