Software Development Exam  >  Software Development Questions  >  What will be the output of the following code... Start Learning for Free
What will be the output of the following code?
def combinations(n, r):
    if r == 0 or n == r:
        return 1
    else:
        return combinations(n - 1, r - 1) + combinations(n - 1, r)
print(combinations(6, 2))
  • a)
    6
  • b)
    10
  • c)
    15
  • d)
    20
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
What will be the output of the following code?def combinations(n, r): ...
The code calculates the number of 'combinations' of 6 objects taken 2 at a time using the combinations function. It uses a recursive approach to calculate the number of combinations. In this case, the number of combinations of 6 objects taken 2 at a time is 15.
View all questions of this test
Explore Courses for Software Development exam

Top Courses for Software Development

What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer?
Question Description
What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer? for Software Development 2025 is part of Software Development preparation. The Question and answers have been prepared according to the Software Development exam syllabus. Information about What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Software Development 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer?.
Solutions for What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Software Development. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free.
Here you can find the meaning of What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer?, a detailed solution for What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice What will be the output of the following code?def combinations(n, r): if r == 0 or n == r: return 1 else: return combinations(n - 1, r - 1) + combinations(n - 1, r)print(combinations(6, 2))a)6b)10c)15d)20Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Software Development tests.
Explore Courses for Software Development exam

Top Courses for Software Development

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev