Python - Function print vs return - whats wrong

All,

I have a basic buzz program written in python with return function. If i change return with print,it works fine but i want to know whats wrong with return statement.Can anyone help me whats wrong with this

#!/usr/bin/python

def div4and6(s,e):
    for i in range(s,e+1):
         if i%4 == 0 and i%6 == 0:
           return "Hello"
         elif i%4 == 0:
           return "Hell"
         elif i%6 == 0:
            return "Hel"
         else:
            return i

a=input("Please input the start and end no: ")
b=input("Please input the start and end no: ")
print div4and6(a,b)
  1. You have indentation errors in your code. Indentation is very important for python.

  2. If python sees a return statement, it will simply goes out of the function back to the caller; regardless of the loop it is in. So your logic would be wrong if it's a return instead of print.

  3. If this is a classwork/homework question, there's a different section in this forum.

balajesuri,

Sorry when i typed the code intentation changed.

However this is the output

Please input the start and end no: 1
Please input the start and end no: 20
1

Whereas i am expecting the following output

1
2
3
Hell
5
Hel
7
Hell
9
10
11
Hello
13
14
15
Hell
17
Hel
19
Hell
None

not sure where it is going wrong

Is this a homework item? Until you answer this question, we are unable to provide much more help.

You know indentation is important in python scripts. But the script you posted has indentation that is different from the code you're using. How do you expect us to help debug your code if you don't show us an accurate representation (in CODE tags) of the code you're using?

Don,

This is not a homework problem. I have corrected the code now its looking good

As balajesuri said, the first time through the loop in your function (with i set to 1) ends with the statement:

return i

and the return statement terminates the function and returns to the caller. If you change all of the return x statements in your function to print x statements and change the call to your function from:

print div4and6(a,b)

to just:

div4and6(a,b)

it looks like you would get what you want.