Search Header Logo

Hunt the bug Quiz

Authored by Vishnu Vardhan

Computers

University

Used 7+ times

Hunt the bug Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

30 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

def is_prime(n):

    if n <= 1:

        return False

    for i in range(2, int(n ** 0.5) + 1):

        if n // i == 0:

            return False

    return True

print(is_prime(1999))  # Output: True

#find the error in this code to get this output ?

Replace // with %

Add +1 to the loop range

Change <= 1 to < 1

Return n instead of True

2.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

def factorial(n):

    result = 1

    for i in range(1, n):  

        result *= i

    return result

print(factorial(5))  # Output: 120

#find the error in this code to get this output ?

Replace (1, n) with (1, n+1)

Change result = 1 to result = 0

Use range(n) instead of range(1, n)

Return i instead of result

3.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

for i in range(1, 6):

    print(" ".join(str(x) for x in range(1, i)))  # Error introduced here

# Output:

1

1 2

1 2 3

1 2 3 4

1 2 3 4

#find the error in this code to get this output

Replace str(x) with x

Change " ".join to "".join

Use range(1, i+1) instead of range(1, i)

Change range(1, 6) to range(1, 5)

4.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

def is_palindrome(s):

    s = s.lower()

    s1 = s[::-1]

    if s == s1:

        return True

    return s1  # Error introduced here

print(is_palindrome("radar"))

#find the error in this code to get this output ?

Remove the if condition entirely

Change s[::-1] to s[:-1]

Use return s instead of return True

Replace return s1 with return False

5.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

def fibonacci(n):

    a, b = 0, 1

    for _ in range(n):  

        a, b = b, a + b

    return a

print(fibonacci(10))  # Output: 34

#find the error in this code to get this output ?

Use range(n-1) instead of range(n)

Replace a + b with a - b

Change return a to return b

Replace a, b = 0, 1 with a, b = 1, 1

6.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

d = {"a": 1, "b": 2}

d.update(["c", 3])  

print(d)  # Output: {'a': 1, 'b': 2, 'c': 3}

#find the error in this code to get this output ?

Change d.update to d.append

Replace ["c", 3] with {"c": 3}

Use d["c"] = 3 instead of d.update

Remove the update line

7.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

def transpose(matrix):

    return [[row[i] for row in matrix] for i in range(len(matrix))]  

matrix = [[1, 2], [3, 4], [5, 6]]

print(transpose(matrix))  # Output: [[1, 3, 5], [2, 4, 6]]

#find the error in this code to get this output ?

Use matrix[i] instead of row[i]

Remove for row in matrix

Replace len(matrix) with len(matrix[0])

Change return to print

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?