📢 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:     def

      mystery(a, b):         if a == 0:             return b         else:             return mystery(b % a, a)     print(mystery(15, 20))     What is the output of this code?
      B 5 Correct Answer Incorrect Answer
      C 15 Correct Answer Incorrect Answer
      D 20 Correct Answer Incorrect Answer
      E Error Correct Answer Incorrect Answer

      Solution

      This is the Euclidean algorithm for finding the Greatest Common Divisor (GCD).     1. mystery(15, 20): a is not 0. Calls mystery(20 % 15, 15) which is mystery(5, 15).     2. mystery(5, 15): a is not 0. Calls mystery(15 % 5, 5) which is mystery(0, 5).     3. mystery(0, 5): a is 0. Returns b, which is 5.     The final output is 5.

      Practice Next
      ask-question