Question #358

What is the output of the code snippet below?
def find_avg(list_num):
    result_sum = 0
    for num in list_num:
        result_sum += num
    result_avg = result_sum/len(list_num)
    
    
find_avg([5, 8, 5])
print(result_avg)

When the control calls print(result_avg) , result_avg , as a local variable whose scope is bound to find_avg , is no longer present in memory. It will throw a NameError exception. (w3schools.com/python/gloss_python_global_variables.asp)


Comment on Disqus:

Question difficulty: πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅