0
0
Prompt Engineering / GenAIml~20 mins

Code generation in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Code Generation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple code generation model snippet
What is the output of this Python code simulating a simple code generation model's token prediction?
Prompt Engineering / GenAI
tokens = ['def', ' ', 'add', '(', 'a', ',', ' ', 'b', ')', ':', '\n', '    ', 'return', ' ', 'a', ' ', '+', ' ', 'b']
predicted = ''.join(tokens)
print(predicted)
A
defadd(a,b):
returna+b
Bdef add(a, b): return a + b
C
def add(a, b):
    return a + b
D
def add(a, b):
return a + b
Attempts:
2 left
💡 Hint
Look carefully at the tokens and how they join with spaces and newlines.
Model Choice
intermediate
1:30remaining
Choosing the right model for code generation
Which model architecture is best suited for generating code snippets given a prompt?
ATransformer-based model
BConvolutional Neural Network (CNN)
CRecurrent Neural Network (RNN) with LSTM
DK-Nearest Neighbors (KNN)
Attempts:
2 left
💡 Hint
Consider models that handle long-range dependencies and context well.
Hyperparameter
advanced
1:30remaining
Effect of temperature on code generation output
In a code generation model, what is the effect of increasing the temperature parameter during sampling?
AImproves the syntax correctness of generated code
BGenerates more deterministic and repetitive code outputs
CDecreases the length of generated code
DGenerates more random and diverse code outputs
Attempts:
2 left
💡 Hint
Think about how temperature affects randomness in sampling.
Metrics
advanced
2:00remaining
Evaluating code generation quality
Which metric is most appropriate to evaluate the functional correctness of generated code snippets?
ANumber of tokens generated per second
BCode execution accuracy on test inputs
CPerplexity of the language model on generated code
DBLEU score comparing generated code to reference code
Attempts:
2 left
💡 Hint
Think about measuring if the code actually works as intended.
🔧 Debug
expert
2:30remaining
Debugging a code generation output error
A code generation model outputs this Python code snippet: "def multiply(a, b):\nreturn a * b" When running, it raises an IndentationError. What is the cause?
Prompt Engineering / GenAI
def multiply(a, b):
return a * b
AThe return statement is not indented inside the function
BThe function name is invalid
CThe multiplication operator is incorrect
DThe function is missing a colon at the end
Attempts:
2 left
💡 Hint
Python requires code blocks to be indented properly.