0
0
Prompt Engineering / GenAIml~10 mins

Multi-step reasoning 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 calculate the mean of a list of numbers.

Prompt Engineering / GenAI
numbers = [4, 8, 15, 16, 23, 42]
mean = sum(numbers) / [1]
Drag options to blanks, or click blank then click option'
Amin(numbers)
Bsum(numbers)
Cmax(numbers)
Dlen(numbers)
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by sum(numbers) instead of the count.
Using max(numbers) or min(numbers) which are unrelated.
2fill in blank
medium

Complete the code to split data into features and labels for training.

Prompt Engineering / GenAI
data = [[5.1, 3.5, 1.4, 0.2, 'setosa'], [6.2, 3.4, 5.4, 2.3, 'virginica']]
features = [row[:[1]] for row in data]
labels = [row[-1] for row in data]
Drag options to blanks, or click blank then click option'
A5
B3
C4
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 which misses one feature.
Using 5 which includes the label.
3fill in blank
hard

Fix the error in the code to train a simple linear regression model using scikit-learn.

Prompt Engineering / GenAI
from sklearn.linear_model import LinearRegression
X = [[1], [2], [3], [4]]
y = [2, 4, 6, 8]
model = LinearRegression()
model.[1](X, y)
Drag options to blanks, or click blank then click option'
Atrain
Bfit
Cpredict
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using train which is not a method in scikit-learn.
Using predict which is for making predictions, not training.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Prompt Engineering / GenAI
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word as the value instead of its length.
Using '<' which selects shorter words.
5fill in blank
hard

Fill all three blanks to filter a dictionary for items with values greater than 10 and convert keys to uppercase.

Prompt Engineering / GenAI
data = {'a': 5, 'b': 15, 'c': 25}
filtered = { [1]: [2] for [3], v in data.items() if v > 10 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using data instead of loop variable for keys.
Not converting keys to uppercase.