Wednesday, 4 December 2019

return statement


Return statement:
#example program for return statement
def add(a,b):
    return(a+b)
d=add(5,4)#function call, return value is stored in d
print(d)

function can take input values as parameters and executes logic, and returns output to the function call with return statement.

#example program for return statement
def prime(n):
    ctr=0
    for i in range(1,n+1):
        if n%i==0:
            ctr+=1
    if ctr==2:
        print(n,"is prime")
    else:
        print(n,"is not prime")
"""output:
>>> prime(3)
3 is prime
>>> prime(4)
4 is not prime
>>> prime(6)
6 is not prime
>>> 
""""
 Assignment function that generates prime numbers:
10
2,3,5,7,11,13,17,19,23,29

Related video: https://youtu.be/EpizFbmfC5s

Prev   Calling a function
Next: A function return more than one value
Related videos: https://youtu.be/SIwAaHwKctY

1 comment:

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(...