Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print numbers from 1 to 10 using a for loop.
Bash Scripting
for i in [1]; do echo "$i" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or parentheses instead of curly braces.
Forgetting the two dots between numbers.
✗ Incorrect
The correct syntax for a range in bash for loops is {start..end}, so {1..10} prints numbers 1 through 10.
2fill in blank
mediumComplete the code to print "Number: X" for each number from 1 to 10.
Bash Scripting
for num in [1]; do echo "Number: $num" done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses or square brackets instead of curly braces.
Missing the two dots between numbers.
✗ Incorrect
The range {1..10} correctly generates numbers 1 to 10 in bash for loops.
3fill in blank
hardFix the error in the for loop to correctly iterate from 1 to 10.
Bash Scripting
for i in [1]; do echo $i done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the curly braces.
Using parentheses or square brackets instead.
✗ Incorrect
The correct syntax for a range in bash is {1..10} with curly braces and two dots.
4fill in blank
hardFill both blanks to create a loop that prints squares of numbers from 1 to 5.
Bash Scripting
for n in [1]; do echo $((n [2] n)) done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of * for multiplication.
Using wrong range like {1..10}.
✗ Incorrect
The loop uses {1..5} to iterate numbers 1 to 5, and * to multiply n by itself for the square.
5fill in blank
hardFill all three blanks to create a loop that prints "Number X is even" for even numbers from 2 to 10.
Bash Scripting
for num in [1]; do if (( num [2] 2 == 0 )); then echo "Number $num is [3]" fi done
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using {1..10} instead of {2..10}.
Using + instead of % for modulus.
Printing wrong word instead of 'even'.
✗ Incorrect
The loop uses {2..10} to iterate numbers from 2 to 10, % to check remainder, and prints 'even' for even numbers.