Page 59 - tp_Modula_v2.0
P. 59
On running the above program, you will get the following output:
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 2: To print a string by calling a function.
Program2.py
File Edit Format Run Options Window Help
#Function Example
def hello(name):
print("Hello "+name+"! How do you do?")
#Calling Function by passing parameter
hello('orange')
On running the above program, you will get the following output:
Output
Hello orange! How do you do?
SOME MORE PROGRAMS
Program 3: To add two numbers using function.
Program3.py
File Edit Format Run Options Window Help
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))
Functions in Python 57

