You are on page 1of 3

Lab 4&5

Python program to demo for passing one and two arguments for same function
Answer:
# Function that takes one argument
def greet_person(name):
print("Hello,", name, "!")

# Function that takes two arguments


def add_numbers(x, y):
result = x + y
print("Sum of", x, "and", y, "is:", result)

# Main function
def main():
# Calling the function with one argument
greet_person("Mariam")

# Calling the function with two arguments


add_numbers(5, 7)

if __name__ == "__main__":
main()
Java a program to add two integers in a function and return the result to the calling
function
Answer:
public class AddTwoIntegers {
// Function to add two integers and return the result
static int add(int num1, int num2) {
return num1 + num2;
}

public static void main(String[] args) {


// Numbers to be added
int a = 5;
int b = 7;

// Call the add function and store the result


int sum = add(a, b);

// Display the result


System.out.println("The sum of " + a + " and " + b + " is: " + sum);
}
}

You might also like