0
0
Intro to Computingfundamentals~10 mins

Loops (repeating actions) 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 print numbers from 1 to 5 using a loop.

Intro to Computing
for i in range(1, [1]):
    print(i)
Drag options to blanks, or click blank then click option'
A6
B5
C10
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 as the end number, which stops at 4.
Using 10, which prints more numbers than needed.
2fill in blank
medium

Complete the code to sum numbers from 1 to 4 using a loop.

Intro to Computing
total = 0
for num in range(1, [1]):
    total += num
print(total)
Drag options to blanks, or click blank then click option'
A4
B5
C6
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 4 as the end number, which excludes 4 from the sum.
Using 6, which sums extra numbers.
3fill in blank
hard

Fix the error in the loop to print each character in the word.

Intro to Computing
word = 'hello'
for [1] in word:
    print(letter)
Drag options to blanks, or click blank then click option'
Aletter
Bword
Cchar
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than in the print statement.
Using the string variable name as the loop variable.
4fill in blank
hard

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

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

Fill all three blanks to create a dictionary of uppercase words with their lengths, filtering words longer than 3 letters.

Intro to Computing
result = [1]: [2] for word in words if len(word) [3] 3}
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of uppercase for keys.
Using < or == instead of > in the condition.