
Hunt the bug Quiz
Authored by Vishnu Vardhan
Computers
University
Used 7+ times

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

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
25 questions
latihan PHP tahap 2
Quiz
•
11th Grade - University
25 questions
MYSQL QUIZ 1
Quiz
•
University
25 questions
IT100 Final Exam Review
Quiz
•
University
25 questions
Java Review
Quiz
•
9th Grade - University
31 questions
Computer System
Quiz
•
12th Grade - University
25 questions
EMPOWERMENT TECHNOLOGY
Quiz
•
KG - University
31 questions
java collections
Quiz
•
University
25 questions
Review ETS Coding
Quiz
•
University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
29 questions
Alg. 1 Section 5.1 Coordinate Plane
Quiz
•
9th Grade
22 questions
fractions
Quiz
•
3rd Grade
11 questions
FOREST Effective communication
Lesson
•
KG
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
Discover more resources for Computers
12 questions
IREAD Week 4 - Review
Quiz
•
3rd Grade - University
7 questions
Fragments, Run-ons, and Complete Sentences
Interactive video
•
4th Grade - University
7 questions
Renewable and Nonrenewable Resources
Interactive video
•
4th Grade - University
10 questions
DNA Structure and Replication: Crash Course Biology
Interactive video
•
11th Grade - University
5 questions
Inherited and Acquired Traits of Animals
Interactive video
•
4th Grade - University
5 questions
Examining Theme
Interactive video
•
4th Grade - University
20 questions
Implicit vs. Explicit
Quiz
•
6th Grade - University
7 questions
Comparing Fractions
Interactive video
•
1st Grade - University