wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

0xDebug - Python

Total questions: 10

Worksheet time: 6mins

Name
Class
Date
1.

The following Code snippet for the function hasCycle, uses hare-tortoise algorithm for detecting cycle in linked list. Read through the code carefully and select the option that is suitable.

a)

There is no issue in the code; it will execute successfully

b)

The ‘while’ condition must be improved by adding some condition

c)

Updating ‘hare’ pointer will directly affect ‘tortoise’ pointer

d)

Line 9 must be updated by “if tortoise == hare”

2.

The code snippet uses binary search algorithm to check if a value is present in the given list. Identify the options true to make the below code to follow binary search algorithm.

To make this code “binary search” work properly the recursion has to be done with proper parameters. Consider the complexityConsider the format: “ Change at Line 8 | Change at Line 10 “

a)

search(a, mid + 1, last, item)    |    search(a, start, mid – 1, item)

b)

search(a, start, mid – 1, item)  |    search(a, mid + 1, last, item)

c)

search(a, start, mid, item)        |     search(a, mid, last, item)

d)

search(a, mid + 1, last, item)    |     search(a, start, mid, item)

3.

The below question is to check, can we able to reach the last element of the array by starting from 0th index of the array. The index has to be incremented by value in that index position. N is the length of the array. ‘arr_step_count’ array contains values (step count) ranging from 0 <= step_count <= ∞

Is there any possibilities for infinite loop in any case of input list whose element value ranges from 0 <= element_value <=

a)

Yes

b)

No

4.

The given code is the solution for finding a number is a palindrome or not.

To make the above code work properly, how many changes has to be made:

a)

No error

b)

Three

c)

Two

d)

One

5.

Read through the following code for Linked List reversal with the following functions.

What must be the order of the lines inside the while loop must follow, to reverse the linked list.

a)

13, 12, 15, 14

b)

14, 12, 15, 13

c)

12, 15, 14, 13

d)

15, 14, 13, 12

6.

Select the Logical Error in the following Code Snippet for the function multiply_matrices.

a)

There is no error

b)

Array A is accessed wrongly

c)

Array B is accessed wrongly

d)

Array result is accessed wrongly

7.

Choose the correct output for the below code snippet

a)

2

b)

1

c)

Runtime Exception of Arithmetic Exception

d)

Compilation error due to divisibility by 0

8.

List the applications of ‘<<’  and  ‘>>’ operator in python.

a)

Multiplication & Division by the powers of 2

b)

Used for alignment of the “print” statement

c)

Used in circular buffers and circular queue

d)

Used for commenting statements

9.

The following code snippet to check whether a given year is leap year or not. For example: If the user enters the year 2020, then the output will be 2020 is a Leap Year.  If the user enters the year 2023, then the output will be 2023 is not a Leap Year.

Find out line containing the logical error and select the option that must be replaced with that line

a)

if (year % 400 == 0)

b)

else if (year % 100 != 0 && year % 4 == 0)

c)

if (year % 4 == 0)

d)

if (year % 100 == 0)

10.

Using the below code snippet, check if the output is right or wrong. If wrong, select the correct output of this code.

a)

The above output is correct.

b)

The above output is wrong, the correct one is “$We$love$Oxdebug$”.

c)

The above output is wrong, the correct one is “We$love$Oxdebug”.

d)

There is an error in the code.