ADVANCED FUNCTIONS ================== PASSING OF TEXT TO FUNCTION =========================== Syntax: def function-name(string-data-object): function-body # Passing of string data to the function # A PROGRAM TO CREATE A FUNCTION WHICH CAN ACCEPT A STRING DATA AND CALCULATE THE NUMBER OF VOWELS IN THE GIVEN STRING DATA./ def countVowels(strData): countVowels = 0 for ch in strData: if ch in "aeiouAEIOU": countVowels = countVowels + 1 return countVowels str1 = input("Enter a string data:") count = countVowels(str1) print("The Number of vowels = ",count) =============================================================== PASSING OF LIST TO FUNCTION =========================== Syntax: def function-name(list-data-object): function-body sum(): ==== is an inbuilt method which we can use to find the sum of group of elements. Syntax: sum(collection with numbers) # Passing of a list to the function as an argument def listFunction(listData): # sumListElements = sum(listData) sumListElements = 0 for i in listData: sumListElements = sumListElements + i return sumListElements ld = eval(input("Enter a list data:")) sumListData = listFunction(ld) print("The Sum of List Elements = ",sumListData) ========================================================= PASSING OF TUPLE TO FUNCTION ============================ Syntax: def function-name(tuple-data-object): function-body # passing a tuple data to a function def tupleFunction(tupleData): index = 0 for i in tupleData: print("The Element of tuple at {} is = {}".format(index,i)) index = index + 1 # tupleFunction((1,3,5,7,9)) # tupleFunction(100,200,300,400,500) a = 100,200,300,400,500 tupleFunction(a) PASSING OF SET TO FUNCTION ========================== Assignment: ========== WAP TO CREATE A FUNCTION WHICH CAN ACCEPT A SET DATA AND FIND THE SMALLEST NUMBER FROM THE GIVEN SET. PASSING OF DICTIONARY TO FUNCTION ================================== Syntax: def function-name(dictionary-object): function-body # PASSING A DICTIONARY TO THE FUNCTION def dictFunction(dictData): print("The name of the student = ",dictData['name']) print("The roll of the student = ",dictData['roll']) print("The marks of the student = ",dictData['marks']) stuRecord = {'name' : 'Aakash', 'roll' : 10, 'marks' : '77.2%'} dictFunction(stuRecord) ================================================================= RETURNING OF STRING FROM FUNCTION ================================= # returning of string from function def function(): a = 100 b = 121 c = 97 d = 234 tupleData = a,b,c,d sumResult = sum(tupleData) average = sumResult/len(tupleData) # approach-1 # result = "The Average of given elements is = ",average # return result # approach-2 # result = "The Average of given elements is = {}".format(average) # return result # approach-3 result = "The Average of the given elements is = %s"%(average) return result print(function())