3. How many 3 digit numbers are divisible by 17? Write a function to print them and return the sum. (The sum being the sum of the 3 digit numbers that are divisible by 17).

4. Write a program that does the following to an image:
changes black pixels to white and white pixels to black
for non-black and non-white pixels, do the following:
reduce the red by 50% if the value of red is above 200
reduce the red by 20% if the value of red is between 100 (inclusive) and 200 (inclusive)
increase the red by 50% if the value of red is below 100
return the total number of pixels increased or decreased by 50% (not including the black & white pixels)
How did you test your program? How do you know that it works? Show a list of test cases that will ensure that every branch of the program is followed.

Using Jython Envirenment for Student


the Q3: I dont know how to sum the answer
Q4, no idea

#===============E 3========================

# This allow any number you want
def dvsble(x,y):  
   for n in range(x,y): 
     sum = 0   
     if n%17 ==0:
      x = n
      sum()
      print n       
     else:      
      n=n+1     
   print sum

Q4:

def color():
  pic = makePicture(pickAFile())
  for x in range(getWidth(pic)):
    for y in range(getHeight(pic)):
      px = getPixel(pic,x,y)
      color = getColor(px)
      if getColor(Color(255,255,255)):       
         setColor(color,Color(0,0,0))
      elif  getColor(0,0,0):
            getColor(255,255,255)
  show(pic)
#===============E 3========================

# This allow any number you want
def dvsble(x,y):  
   for n in range(x,y): 
     sum = 0   
     if n%17 ==0:
      x = n
      sum()
      print n       
     else:      
      n=n+1     
   print sum

Some comments to help going forward:

  1. Are the parameter choice correct considering restrictions of this request
  2. Line 5 task said range of three number integers, what is smallest one and what biggest?
  3. what happens on line at beginning of loop at line 6, is it what you want
  4. where is x used?
  5. line 9: value of sum is 0 so you are using 0 as function without parameters
  6. lines 10 and 13 are printing values of n and the address of built in sum, which you set 0 at line 0
  7. There is contradiction between line 5 and 12 both advancing the value of n

I would suggest to collect all correct numbers to list and returning them from the function if you learned about lists allready.
I would not replace the builtin function sum with integer even locally in function. It is efficient way of doing sum at one go from collected numbers (this task is actually one line expression with experienced coders with generator expression)

def dvsble():  
# use the sum in list
   l = [n for n in range(100,1000) if n%17 == 0]
   print l
   return sum(l)

I know how to do Q3

But still no idea for Q4

code for Q4? So we help you to finish.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.