NEW
Font size
WorksheetsRound 2 Debug-The-Code
Total questions: 15
Worksheet time: 30mins
The following code is supposed to print "mello world"
s = "hello world"
s[0] = "m"
print(s)
is there an error?
Error: Cant change immutable variables
No error
Prints "hello world"
error missing semicolon
Fill in the blank to get the 120 as output.
calc
foo
none of these
What should be filled in the blank to get [3, 2, 1] as output?
<
>
<=
>=
The complexity of bubble sort algorithm is?
O(n)
O(log n)
O(n^2)
O(n log n)
What should be filled in the blank to get 15 as output
length()
len()
length
size
Which of the following lines of code contains an error in Java?
int x = 5;
double y = 3.14;
String z = "hello";
boolean w = True;
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)
Only A
Both A and B
Both A and D
None of the above
What is the error in the given Python code?
Syntax error: too many arguments passed to the function
Syntax error: missing comma between function arguments
Logic error: the function should return x - y instead of x + y
Runtime error: variable not defined
What is the correct way to print the following in python:
Hello World
print("Hello") print("World")
print("Hello") print(" World")
print("Hello", end = " ")
print("World")
print("Hello", end = "\n")
print("World")
Find the error in the given Java code
Runtime error: array index out of bounds
Syntax error: missing semicolon after the print statement
Logic error: should use charAt() method instead of array indexing
No error
Find the error in this code
Logic error: the function should multiply x and y if both are positive
Syntax error: missing parentheses after the if statements
Syntax error: missing colon after the if statements
Runtime error: variable not defined
What is the correct way to find all numbers between 1 and 1000 that have 6 in them
print([num for num in range(1, 1000) if 6 in num])
print([num for num in range(1, 1000) if "6" in str(num)])
print([num for num in range(1, 1000) if "6" in num])
None of these
Find the error in this prime number checking code snippet
No error
The loop should run from 2 to num+1
There shouldn't be a break statement
There should be modulo in the if(num // i) conditional
What is the correct way to find the cubes of numbers from 1 to 10?
print(list(map(lambda x : x*x*x, range(1, 11))))
print(list(map(lambda x*x*x, range(1, 11))))
print(list(map(x*x*x, range(1, 11))))
None of these
What will be the output of this code snippet?
Syntax Error
9
Runtime Error
5
