Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a number is positive.
MATLAB
if [1] > 0 disp('Positive number'); end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the code.
✗ Incorrect
The variable num is used to check if it is greater than zero.
2fill in blank
mediumComplete the code to execute the else block when the number is not positive.
MATLAB
if num > 0 disp('Positive'); [1] disp('Not positive'); end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
elseif without a condition.✗ Incorrect
The else keyword runs the code when the if condition is false.
3fill in blank
hardFix the error in the loop to print numbers from 1 to 5.
MATLAB
for i = 1:[1] disp(i); end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 6 as the upper limit.
✗ Incorrect
The loop should run from 1 to 5, so the upper limit is 5.
4fill in blank
hardFill both blanks to create a loop that prints even numbers from 2 to 10.
MATLAB
for num = [1]:[2]:10 disp(num); end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the step value, which prints all numbers.
✗ Incorrect
The loop starts at 2 and increments by 2 to print even numbers.
5fill in blank
hardFill all three blanks to create a conditional that prints 'Even' or 'Odd' for a number.
MATLAB
if mod([1], [2]) == [3] disp('Even'); else disp('Odd'); end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the remainder to check for even numbers.
✗ Incorrect
The mod function checks if num divided by 2 has remainder 0 (even).