Function

Python Quiz for Functions – 02

Python Quiz for Functions

Functions in Python enable programmers to group related statements together, making the code more readable, reusable, and efficient. Whether you’re a beginner trying to grasp the basics of function syntax or an experienced coder aiming to test your understanding, this Python quiz for functions is designed to challenge and educate you. From simple function declarations to intricate details about parameters and return values, get ready to put your Python knowledge to the test!

0%
8

Python Functions – 02

Level: Intermediate

1 / 10

1. How do you specify a default value for a parameter?

2 / 10

2. What does the ‘pass’ statement do in a function?

3 / 10

3. What does the *args syntax in function arguments mean?

4 / 10

4. What is the output of the following code:

def greet(name):
  """This function greets the person passed in as a parameter."""
  return f"Hello, {name}!"

print(greet("Alice"))

5 / 10

5. What is the output of the following code:

def calculate_sum(*args):

  """This function calculates the sum of a variable number of arguments."""
  total = 0
  for num in args:
    total += num
  return total

print(calculate_sum(1, 2, 3, 4, 5))

6 / 10

6. What is the output of the following code:

square = lambda x: x**2
print(square(4)) 

7 / 10

7. What is the output of the following code:

def person_info(name, age, city):
  """This function displays information about a person."""
  print(f"Name: {name}, Age: {age}, City: {city}")

# Example usage:
person_info(name="Alice", age=30, city="New York")

8 / 10

8. What is the result of executing the following Python code?

def add(x,y): 
  global z
  z = x + y
  print(z)
add(1,2)

9 / 10

9. What does the **kwargs syntax in function arguments mean?

10 / 10

10. What is the output of the following code:

def factorial(n):
  """This function calculates the factorial of a number using recursion."""
  if n == 0:
    return 1
  else:
    return n * factorial(n-1)

# Example usage:
print(factorial(5))

Your score is

0%