0% found this document useful (0 votes)
10 views6 pages

Debugging Questions

The document presents a debugging challenge with a set of 15 programming questions in Python and Java, categorized by difficulty levels. Each question describes a specific bug in the code that needs to be identified and fixed. The document includes spaces for participants to fill in their details and the bugs they found.

Uploaded by

ssreeba94
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views6 pages

Debugging Questions

The document presents a debugging challenge with a set of 15 programming questions in Python and Java, categorized by difficulty levels. Each question describes a specific bug in the code that needs to be identified and fixed. The document includes spaces for participants to fill in their details and the bugs they found.

Uploaded by

ssreeba94
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Debugging Challenge

Symposium — Python & Java Problem Set

Name Year / Dept

____________________________________ ____________________________________

College Name Register No.

____________________________________ ____________________________________

15 Questions 2 Languages Easy · Medium · Hard

Question 1 Easy Python

This function should print all elements of the list. Find and fix the bug.

def print_all(items):
for i in range(1, len(items)):
print(items[i])

print_all([10, 20, 30, 40])

Bug found: _________________________________________________________________

Question 2 Easy Java

This method should return true if the input equals "hello". Find and fix the bug.

public boolean isHello(String s) {


return s == "hello";
}

Bug found: _________________________________________________________________

Question 3 Easy Python

This function should return "pass" if score >= 50, else "fail". It always returns None for passing
scores. Find and fix the bug.
def result(score):
if score >= 50:
status = "pass"
else:
status = "fail"
return status

print(result(30))
print(result(75))

Bug found: _________________________________________________________________

Question 4 Easy Java

This loop should print numbers 1 to 5. It runs forever. Find and fix the bug.

public class Main {


public static void main(String[] args) {
int i = 1;
while (i <= 5) {
[Link](i);
i--;
}
}
}

Bug found: _________________________________________________________________

Question 5 Easy Python

This program should add a user-entered number to 10 and print the result. It crashes. Find and fix the
bug.

num = input("Enter a number: ")


print(num + 10)

Bug found: _________________________________________________________________

Question 6 Medium Java

This code should print all array elements. It throws an exception on the last iteration. Find and fix the
bug.
public class Main {
public static void main(String[] args) {
int[] nums = {1, 2, 3, 4, 5};
for (int i = 0; i <= [Link]; i++) {
[Link](nums[i]);
}
}
}

Bug found: _________________________________________________________________

Question 7 Easy Python

This function should return the price after applying a 10% discount. The output is always wrong. Find
and fix the bug.

def apply_discount(price):
discount = price / 10
return price - discount / 100

print(apply_discount(200))
print(apply_discount(500))

Bug found: _________________________________________________________________

Question 8 Medium Java

This method should return the average of two numbers as a decimal. It always returns a whole
number. Find and fix the bug.

public double average(int a, int b) {


return (a + b) / 2;
}

[Link](average(5, 4));

Bug found: _________________________________________________________________

Question 9 Medium Python

This function should return the grade for a student. It crashes if the student is not found. Find and fix
the bug.
grades = {"Alice": "A", "Bob": "B"}

def get_grade(name):
return grades[name]

print(get_grade("Charlie"))

Bug found: _________________________________________________________________

Question 10 Medium Java

This code should print the sum of numbers 1 to 5. It does not compile. Find and fix the bug.

public class Main {


public static void main(String[] args) {
int sum;
for (int i = 1; i <= 5; i++) {
sum += i;
}
[Link](sum);
}
}

Bug found: _________________________________________________________________

Question 11 Easy Java

This method should print whether each number is even or odd. The output is reversed. Find and fix
the bug.
public class EvenOdd {
public static void check(int[] nums) {
for (int n : nums) {
if (n % 2 == 0)
[Link](n + " is Odd");
else
[Link](n + " is Even");
}
}

public static void main(String[] args) {


check(new int[]{1, 2, 3, 4, 5});
}
}

Bug found: _________________________________________________________________

Question 12 Medium Java

This method should return the largest number in the array. It fails for all-negative arrays. Find and fix
the bug.

public class MaxFinder {


public static int findMax(int[] nums) {
int max = 0;
for (int n : nums) {
if (n > max)
max = n;
}
return max;
}

public static void main(String[] args) {


[Link](findMax(new int[]{-5, -3, -8, -1}));
}
}

Bug found: _________________________________________________________________

Question 13 Hard Python

This function should compute the factorial of n. It crashes with a recursion error. Find and fix the bug.
def factorial(n):
return n * factorial(n - 1)

print(factorial(5))

Bug found: _________________________________________________________________

Question 14 Medium Python

This function should return True if a word is a palindrome. It gives wrong results for mixed-case
words. Find and fix the bug.

def is_palindrome(word):
return word == word[::-1]

print(is_palindrome("Racecar"))
print(is_palindrome("madam"))
print(is_palindrome("Level"))

Bug found: _________________________________________________________________

Question 15 Medium Python

This function should print the first n numbers of the Fibonacci series. The output is incorrect. Find and
fix the bug.

def fibonacci(n):
a, b = 0, 1
for i in range(n):
print(a)
a = b
b = a + b

fibonacci(8)

Expected output: 0 1 1 2 3 5 8 13

Bug found: _________________________________________________________________

You might also like