What will be the output of the following Python code? [code]def getMonth(m): if m<1 or m>12: raise ValueError("Invalid")

What will be the output of the following Python code?
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”)
 
Answer: 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.
 

Tìm kiếm

Back
Top