Question #357

What is the output of the code snippet below?
result = 0


def find_sum(num1, num2):
    if num1 != num2:
        result = num1+num2
    else:
        result = 2*(num1+num2)
        
        
find_sum(3, 4)
print(result)
find_sum(5, 5)
print(result)

In both calls of the find_sum() function, result is only modified within the scope of the function (it doesn't have the global keyword). Within the scope of the module, result still equals to 0. (w3schools.com/python/gloss_python_global_variables.asp)


Comment on Disqus:

Question difficulty: ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต