What will be the output of the following Python code?

def getMonth(m):
    if m<1 or m>12:
        raise ValueError("Invalid")
    print(m)
getMonth(6)

a) ValueError
b) Invalid
c) 6
d) ValueError(“Invalid”)

1 thought on “What will be the output of the following Python code?”

  1. c
    Explanation: In the code shown above, since the value passed as an argument to the function is between 1 and 12 (both included), hence the output is the value itself, that is 6. If the value had been above 12 and less than 1, a ValueError would have been thrown.

Leave a Comment