Thursday , September 19 2024

What is the output of the following snippet? def fun(inp=2, out=3): return inp * out print(fun(out=2))

Questions BankCategory: Python Essentials 1What is the output of the following snippet? def fun(inp=2, out=3): return inp * out print(fun(out=2))
What is the output of the following snippet?

def fun(inp=2, out=3):
    return inp * out
 
 
print(fun(out=2))
  • 6
  • 4
  • the snippet is erroneous
  • 2

Explanation: Let’s analyze the code:

  • the fun function is invoked, and the argument used is out = 2, which replaces the predefined value of out = 3,
  • the fun function takes the predefined value of inp = 2, since it is not defined in the invocation of the function,
  • the fun function performs the operation 2*2 and returns it,
  • the print function shows 4 on the console.

More Questions: Python Essentials 1 – Module 4 Test
More Questions: Python Essentials 1 (PE1) Course Final Test