Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Currying Sum Function
00:00
5 left

Currying Sum Function

MediumPython

Problem

Implement a curried sum function like sum(2)(3) that returns the result.

The function should return a closure when called with one argument, while also supporting direct evaluation as sum(a, b) for standard automated testing. Inputs are numeric, and the result must be their sum.

Constraints

  • a and b are integers or floating-point numbers
  • When using curried syntax, the first call supplies a and the second call supplies b
  • The result is the numeric sum of the two operands

Function Signature

def sum(a, b=None):
Interviewer

Your question is Currying Sum Function. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.