Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Unit III : Assessment: Q & A (Selected) 2020 True or False Questions 1. True or False? In Python, program routines are known as functions. Answer True 2. True or False? A function is a named group of instructions performing some task. Answer True 5. True or False? All functions are designed to return a value. Answer False Fill in the blanks 35. A __________ is a named group of instructions performing some task. Answer Routine 38. The identifiers in a function meant to receive the arguments passed to it are called _________________________________. Answer Formal parameters(parameters) 47. ________________ arguments correspond with the associated parameters in a function call by their name. Answer: keyword 1 Department of Computer Science & Engg, PESU Unit III : Assessment: Q & A (Selected) 2020 Match the following 51. (a) Routine (b) function (c) formal parameter (d) actual argument (e) function invocation value passed to a function when called(d) A named group of instructions performing some task(a) a function call, in which actual arguments are provided(e) Python’s version of a program routine(b) an identifier provided in a function header(c) Questions 53. Explain the function arguments in python . Answer Data can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. There are various types of Python arguments functions 1) Default Argument – The arguments passed in a function can have default values. This is done using the assignment operator in python(=). When we call a function without a value for an argument, its default value (as mentioned) is used. Eg - def greeting(name='User'): print(f"Hello, {name}") >>> greeting('Shaun') // gives output hello Shaun When we call greeting() without an argument, the name takes on its default value- ‘User’. 2) Keyword Arguments - With keyword arguments, we can change the order of passing the arguments without any consequences. Eg - def divide(a,b): return a/b >>> divide(3,2) 2 Department of Computer Science & Engg, PESU Unit III : Assessment: Q & A (Selected) 2020 This function can be called with arguments in any order, as long as we specify which value goes into what like in the previous example the function call can be invoked as divide(a=1,b=2) or divide(b=2,a=1) as both gives the same output 3) Arbitrary Arguments- When we are not sure of how many arguments can be passed to a function then we use an asterisk (*) before an argument name. Eg - def sayhello (*names): for name in names: print("Hello, {name}") Now when we invoke the function with any number of arguments like sayhello('Karan','Arjun','Megha') , the names will be iterated using the for loop and printed Programming Exercise 58. Write a Python function named zeroCheck that is given three integers, and returns true if any of the integers is 0, otherwise it returns false Answer def zeroCheck(x, y, z): if x == 0 or y == 0 or z == 0: return True else: return False zeroCheck(3,5,7) zeroCheck(3,0,7) 3 Department of Computer Science & Engg, PESU