A function might have multiple return statements. It can return one value in an if statement and another value in an else statement. It’s important to keep in mind that the function stops its execution as soon as it returns a value. As soon as the function reaches a return statement, the program continues its execution from the place where the function was called:
def process_only_even(n):
if n % 2 == 1:
return 'This was an odd number!'
print('Very interesting number ...', n)
n += 18
print('Adding 18 will result in:', n)
return n
print(process_only_even(5))
# This was an odd number!
print(process_only_even(6))
# Very interesting number ... 6
# Adding 18 will result in: 24
# 24
So, the function returns only once, and the program continues its execution from the point where the function was called.
This is especially handy if you can return a value in a loop, and therefore, both the loop and the function will stop at that point and the program will get back to where the function was called from. We can avoid using break in loops like that.
Challenge
We will call a number “special” if it’s even and the sum of its last two digits is 7.
Implement a function is_special(n) that would return True if n is special and False otherwise. If the number is not “special”, the function should also print Not special in the output before returning.
The input contains a single integer n (100 ≤ n ≤ ).
The program should print Yes if n is special and No otherwise. In the case of printing No, the program should also print Not special before the No.