wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Round 2 Debug-The-Code

Total questions: 15

Worksheet time: 30mins

Name
Class
Date
1.

The following code is supposed to print "mello world"

s = "hello world"

s[0] = "m"

print(s)

is there an error?

a)

Error: Cant change immutable variables

b)

No error

c)

Prints "hello world"

d)

error missing semicolon

2.

Fill in the blank to get the 120 as output.

a)

calc

b)

foo

c)

print

d)

none of these

3.

What should be filled in the blank to get [3, 2, 1] as output?

a)

<

b)

>

c)

<=

d)

>=

4.

The complexity of bubble sort algorithm is?

a)

O(n)

b)

O(log n)

c)

O(n^2)

d)

O(n log n)

5.

What should be filled in the blank to get 15 as output

a)

length()

b)

len()

c)

length

d)

size

6.

Which of the following lines of code contains an error in Java?

a)

int x = 5;

b)

double y = 3.14;

c)

String z = "hello";

d)

boolean w = True;

7.

Which of the following lines of code contains an error in Python?

A. x = 5

B. y = "hello"

C. z = [1, 2, 3]

D. w = (4, 5, 6)

a)

Only A

b)

Both A and B

c)

Both A and D

d)

None of the above

8.

What is the error in the given Python code?

a)

Syntax error: too many arguments passed to the function

b)

Syntax error: missing comma between function arguments

c)

Logic error: the function should return x - y instead of x + y

d)

Runtime error: variable not defined

9.

What is the correct way to print the following in python:

Hello World

a)

print("Hello") print("World")

b)

print("Hello") print(" World")

c)

print("Hello", end = " ")

print("World")

d)

print("Hello", end = "\n")

print("World")

10.

Find the error in the given Java code

a)

Runtime error: array index out of bounds

b)

Syntax error: missing semicolon after the print statement

c)

Logic error: should use charAt() method instead of array indexing

d)

No error

11.

Find the error in this code

a)

Logic error: the function should multiply x and y if both are positive

b)

Syntax error: missing parentheses after the if statements

c)

Syntax error: missing colon after the if statements

d)

Runtime error: variable not defined

12.

What is the correct way to find all numbers between 1 and 1000 that have 6 in them

a)

print([num for num in range(1, 1000) if 6 in num])

b)

print([num for num in range(1, 1000) if "6" in str(num)])

c)

print([num for num in range(1, 1000) if "6" in num])

d)

None of these

13.

Find the error in this prime number checking code snippet

a)

No error

b)

The loop should run from 2 to num+1

c)

There shouldn't be a break statement

d)

There should be modulo in the if(num // i) conditional

14.

What is the correct way to find the cubes of numbers from 1 to 10?

a)

print(list(map(lambda x : x*x*x, range(1, 11))))

b)

print(list(map(lambda x*x*x, range(1, 11))))

c)

print(list(map(x*x*x, range(1, 11))))

d)

None of these

15.

What will be the output of this code snippet?

a)

Syntax Error

b)

9

c)

Runtime Error

d)

5