Hunt the bug Quiz

Hunt the bug Quiz

University

30 Qs

quiz-placeholder

Similar activities

PyWars: Compete For Glory

PyWars: Compete For Glory

University

30 Qs

Takeshi's Castle Code bingo

Takeshi's Castle Code bingo

University

25 Qs

Python Final Prep

Python Final Prep

University

32 Qs

Stack and Queue

Stack and Queue

University

25 Qs

Python and ML Basics

Python and ML Basics

6th Grade - University

30 Qs

Python Module 1

Python Module 1

University

25 Qs

PYTHON CONTEST

PYTHON CONTEST

University

25 Qs

String in C Programming

String in C Programming

University

26 Qs

Hunt the bug Quiz

Hunt the bug Quiz

Assessment

Quiz

Computers

University

Hard

Created by

Vishnu Vardhan

Used 7+ times

FREE Resource

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

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?