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 ?
Hunt the bug Quiz
Quiz
•
Computers
•
University
•
Hard
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
25 questions
PYTHON CONTEST
Quiz
•
University
25 questions
Workshop Quiz
Quiz
•
University
30 questions
conditions function in python
Quiz
•
University
25 questions
PYTHON CONTERST 3
Quiz
•
University
25 questions
Introduction to Python
Quiz
•
KG - University
25 questions
UTS Algoritma dan Pemrograman
Quiz
•
University
25 questions
python_quiz
Quiz
•
University
30 questions
PBO Lanjut 2025
Quiz
•
University
15 questions
Character Analysis
Quiz
•
4th Grade
17 questions
Chapter 12 - Doing the Right Thing
Quiz
•
9th - 12th Grade
10 questions
American Flag
Quiz
•
1st - 2nd Grade
20 questions
Reading Comprehension
Quiz
•
5th Grade
30 questions
Linear Inequalities
Quiz
•
9th - 12th Grade
20 questions
Types of Credit
Quiz
•
9th - 12th Grade
18 questions
Full S.T.E.A.M. Ahead Summer Academy Pre-Test 24-25
Quiz
•
5th Grade
14 questions
Misplaced and Dangling Modifiers
Quiz
•
6th - 8th Grade