📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store

    • Question

      Consider the following Python code snippet:    

      def calculate_sum(a, b):         result = a + b         return result     x = 5     y = 10     total = calculate_sum(x, y)     print(total)     What is the value of result immediately before return result is executed inside calculate_sum when calculate_sum(x, y) is called?
      A 5 Correct Answer Incorrect Answer
      B 10 Correct Answer Incorrect Answer
      C 15 Correct Answer Incorrect Answer
      D None Correct Answer Incorrect Answer
      E The value is undefined. Correct Answer Incorrect Answer

      Solution

      1.  x is assigned 5, y is assigned 10.     2.  calculate_sum(x, y) is called, so a becomes 5 and b becomes 10.     3.  Inside calculate_sum, result = a + b becomes result = 5 + 10, so result is 15.     4.  Then return result is executed, returning 15.

      Practice Next
      ask-question