Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Define a function that adds two numbersE02. Write a function that returns a greetingE03. Implement a function to find the maximum of threeE

Problem No 1

Define a function that adds two numbers

Easy

6 minute session

Summary

Write a simple function that returns the sum of two numbers.

Problem statement

Implement a function named add that accepts two parameters (a and b) and returns their sum. The function should work with integers and floats. Do not print the result; return it so it can be used by other code.

Task

Create a function add(a, b) that takes two numeric values and returns their sum.

Examples

Add two integers

Input

add(2, 3)

Output

5

Explanation

2 + 3 = 5, so the function returns 5.

Input format

Call the function as add(a, b) where a and b are numbers (int or float).

Output format

Return the numeric sum of a and b.

Constraints

Do not use print. The function should return a value. Handle both integers and floats.

Samples

Sample input 0

add(10, 5)

Sample output 0

15

Explanation 0

10 + 5 = 15

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

02:06 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.