ExamHoot

Predict the output of the following code where Hari defines a function with default parameters and calls it multiple times with different arguments

def calculate_total(price, quantity=1, discount=0):
    total = price * quantity - discount
    return total

print(calculate_total(100))
print(calculate_total(100, 3))
print(calculate_total(100, 2, 50))
  1. 100\n300\n150

  2. 100\n100\n100

  3. 100\n300\n50

  4. 300\n300\n150

Show answer & explanation

Correct answer

100\n300\n150

Explanation

The function uses default parameters: quantity defaults to 1 and discount to 0. First call: 100*1-0=100. Second call: 100*3-0=300. Third call: 100*2-50=150.

Written by ExamHoot EditorialPublished · Updated

All 30 Functions and Parameters questions

  1. 1.What is the primary purpose of defining functions in Python programming?
  2. 2.What keyword is used to define a function in Python?
  3. 3.What does the return statement do in a Python function?
  4. 4.What are parameters in a function definition?
  5. 5.What is the difference between parameters and arguments in Python functions?
  6. 6.What will be the output when the following function is called with the given arguments?
  7. 7.What is a default parameter in Python functions and how is it useful?
  8. 8.Predict the output of this function call with default parameters
  9. 9.What does the following code snippet print when executed?
  10. 10.What is the scope of a variable defined inside a function in Python?
  11. 11.What will be printed when this code is executed?
  12. 12.What is a positional argument in a function call?
  13. 13.Predict what this code will output
  14. 14.What happens when a function does not have a return statement in Python?
  15. 15.What will be the output of calling this function?
  16. 16.What is the primary purpose of using parameters in a Python function?
  17. 17.What will be the output when Rajesh calls the function with the provided code snippet?
  18. 18.How does Python differentiate between positional arguments and keyword arguments when calling a function?
  19. 19.What will be the output of Priya's code that demonstrates default parameter values?
  20. 20.Predict what happens when Vikram executes this function with variable scope considerations?
  21. 21.What is the difference between a function definition and a function call in Python?
  22. 22.What will Ananya observe when she runs this function that returns multiple values?
  23. 23.How does Python handle the case when you pass fewer arguments than the number of parameters without default values?
  24. 24.What will be the output when Karthik executes this code involving function parameters and arithmetic operations?
  25. 25.Predict the behavior when Sneha defines a function with the same parameter name as a global variable?
  26. 26.What is the primary purpose of using parameters in a function definition in Python?
  27. 27.Predict the output of the following code where Hari defines a function with default parameters and calls it multiple times with different…
  28. 28.What will be the output when Prasath runs this code that uses both positional and keyword arguments in function calls?
  29. 29.Identify and explain the bug in Rajesh's function that is supposed to calculate the sum of numbers, but produces incorrect results when…
  30. 30.What will be the output when Divya executes this code that demonstrates the difference between mutable and immutable parameter types in…