Compare the following two Python codes shown below and state the output if the input entered in each case is -6?

CODE 1
import math
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))
 
CODE 2
num=int(input("Enter a number of whose factorial you want to find"))
print(math.factorial(num))

a) ValueError, NameError
b) AttributeError, ValueError
c) NameError, TypeError
d) TypeError, ValueError

1 thought on “Compare the following two Python codes shown below and state the output if the input entered in each case is -6?”

  1. a
    Explanation: The first code results in a ValueError. This is because when we enter the input as -6, we are trying to find the factorial of a negative number, which is not possible. The second code results in a NameError. This is because we have not imported the math module. Hence the name ‘math’ is undefined.

Leave a Comment