# Buggy program to print out the prime numbers between 2 and 100 # CS 1 debugging example by Devin Balkcom, April 4 2015 possible_prime = 2 print "Prime numbers between 2 and 100: " while possible_prime < 100: possible_factor = 2 # bug 2 # start by assuming the number is prime. prime = True # then use a loop to test whether that is correct by checking possible integer factors while possible_factor < possible_prime: # bug 4 # If the number is evenly divisible by the possible factor, then it's not a prime if possible_prime % possible_factor == 0: # bug 3 prime = False # Don't need to check any more factors. # Terminate the loop early: break possible_factor += 1 if prime: print str(possible_prime) + " " possible_prime += 1 # bug #1