Page 82 - Touhpad Ai
P. 82
print("Calling Type2 function")
add2 (12, 16)
print("Calling Type3 function")
result = add3 (20,30)
print(result)
Output:
Calling Type1 function
Enter the first number: 4
Enter the second number: 5
The sum of both the numbers is 9
Calling Type2 function
The sum of both the numbers is 28
Calling Type3 function
50
Program 24: To print a string by calling a function.
#Function Example
def hello(name):
print("Hello "+name+"! How do you do?")
#Calling Function by passing parameter
hello('orange')
Output:
Hello orange! How do you do?
Program 25: To add two numbers using function.
def add(a,b):
sum=a+b
return sum;
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
print("The sum is", add(num1, num2))
Output:
Enter first number: 5
Enter second number: 6
The sum is 11
Program 26: To find the product of two numbers using function.
def prod(a,b):
multi=a*b;
return multi;
num1=int(input("Enter first number: "))
num2=int(input("Enter second number: "))
print("The product is", prod(num1, num2))
Output:
Enter first number: 5
Enter second number: 4
The product is 20
80 Touchpad Artificial Intelligence - XI

