0
0
Blockchain / Solidityprogramming~10 mins

For and while loops in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to loop through the numbers 1 to 5 and print each number.

Blockchain / Solidity
for i in range(1, [1]):
    print(i)
Drag options to blanks, or click blank then click option'
A6
B5
C4
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 5 as the end number, which excludes 5 from the loop.
2fill in blank
medium

Complete the code to create a while loop that stops when the variable count reaches 3.

Blockchain / Solidity
count = 0
while count [1] 3:
    print(count)
    count += 1
Drag options to blanks, or click blank then click option'
A>
B<
C==
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which causes an infinite loop or no loop at all.
3fill in blank
hard

Fix the error in the for loop to correctly print each item in the list.

Blockchain / Solidity
items = ['block', 'chain', 'loop']
for [1] in items:
    print(item)
Drag options to blanks, or click blank then click option'
Aitem
Bi
Cblock
Dchain
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than in the print statement.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 4 letters.

Blockchain / Solidity
lengths = {word: [1] for word in words if len(word) [2] 4}
Drag options to blanks, or click blank then click option'
Alen(word)
B<
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' which selects shorter words.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only if the value is greater than 10.

Blockchain / Solidity
result = [1]: [2] for k, v in data.items() if v [3] 10}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using the key directly without uppercase.
Using '<' instead of '>' for filtering.