1. What is the process of dividing a computer program into separate independent blocks of code known as?
2. What is the purpose of functions in programming?
3. Which of the following statements is true about functions?
4. What is the syntax to define a function in Python?
5. What does the 'return' statement do in a function?
6. What is the term for a value passed to a function during the function call?
7. What is a user-defined function?
8. In the function definition `def add(a, b):`, what are `a` and `b`?
9. Which keyword is used to create a function in Python?
10. What is the output of the following code? Python Code: def greet(name): return "Hello, " + name print(greet("Alice"))
11. How do you call a function named `my_function` in Python?
12. What will be the output of the following code? Python Code: def add(a, b): return a + b result = add(3, 5) print(result)
13. What is an advantage of using functions in a program?
14. What is the output of the following code? Python Code: def multiply(a, b): return a * b print(multiply(2, 4))
15. Which of the following is not a characteristic of a function?
16. What is the main advantage of breaking a program into smaller functions?
17. What is the keyword used to return a value from a function in Python?
18. What is the output of the following code? Python Code: def subtract(a, b): return a - b print(subtract(10, 3))
19. Which of the following best describes a function?
20. How do you define a function with no parameters?
21. What will be the output of the following code? Python Code: def divide(a, b): return a / b print(divide(10, 2))
22. What is a function call?
23. Which of the following is an invalid function name in Python?
24. What is the output of the following code? Python Code: def say_hello(): print("Hello, World!") say_hello()
25. What is the main purpose of the `def` keyword in Python?
26. Which of the following functions is used to find the length of a list in Python?
27. What will be the output of the following code? Python Code: def square(x): return x * x print(square(3))
28. What is a parameter in the context of functions?
29. Which of the following is an example of a function with a return value?
30. What will be the output of the following code? Python Code: def concat(str1, str2): return str1 + str2 print(concat("Hello, ", "World!"))
31. How do you pass multiple arguments to a function in Python?
32. What will be the output of the following code? Python Code: def power(base, exp): return base**exp print(power(2, 3))
33. What is the main purpose of using functions in programming?
34. What will be the output of the following code? Python Code: def add_five(x): return x + 5 print(add_five(10))
35. What is the keyword used to define a function in Python?
36. What will be the output of the following code? Python Code: def greet(): return "Hello!" print(greet())
37. How do you specify default values for parameters in a function?
38. What is the output of the following code? Python Code: def increment(n): n += 1 return n print(increment(7))
39. Which statement is true regarding a function with multiple return statements?
40. What will be the output of the following code? Python Code: def double(x): return x * 2 result = double(4) print(result)
41. Which of the following is a correct way to document a function in Python?
42. What will be the output of the following code? Python Code: def subtract(a, b): return a - b print(subtract(15, 5))
43. What is the term used for a function defined inside another function?
44. What will be the output of the following code? Python Code: def sum_numbers(a, b): return a + b result = sum_numbers(3, 4) print(result)
45. What is the output of the following code? Python Code: def identity(x): return x print(identity("Python"))
46. How do you ensure a function has a variable number of arguments in Python?
47. What will be the output of the following code? Python Code: def repeat_string(s, n): return s * n print(repeat_string("Hi", 3))
48. Which of the following is not a valid Python function?
49. What is the primary purpose of a lambda function in Python?
50. What will be the output of the following code? Python Code: def add(a, b=5): return a + b print(add(3))

No comments: