0
0
Intro to Computingfundamentals~10 mins

Arrays and lists in Intro to Computing - 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 list of numbers from 1 to 5.

Intro to Computing
numbers = [[1]]
Drag options to blanks, or click blank then click option'
A1, 2, 3, 4, 5
B1 2 3 4 5
C(1, 2, 3, 4, 5)
D{1, 2, 3, 4, 5}
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of commas between numbers.
Using parentheses or curly braces instead of square brackets.
2fill in blank
medium

Complete the code to access the third element in the list named 'fruits'.

Intro to Computing
third_fruit = fruits[[1]]
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3 as the index which is actually the fourth element.
Confusing list indexes with counting numbers.
3fill in blank
hard

Fix the error in the code to add the number 10 to the end of the list 'scores'.

Intro to Computing
scores.[1](10)
Drag options to blanks, or click blank then click option'
Ainsert
Bappend
Cadd
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add' which is not a list method.
Using 'insert' without specifying the position.
Using 'extend' which expects an iterable, not a single value.
4fill in blank
hard

Fill both blanks to create a list of squares for numbers 1 to 5.

Intro to Computing
squares = [x[1]2 for x in range(1, [2])]
Drag options to blanks, or click blank then click option'
A**
B+
C6
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication instead of exponentiation for squaring.
Using 5 in range which excludes the number 5.
5fill in blank
hard

Fill all three blanks to create a dictionary with words as keys and their lengths as values, only for words longer than 3 letters.

Intro to Computing
lengths = { [1] : [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Dlen(words)
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(words) which is the length of the whole list, not each word.
Using different variable names inconsistently.