Computer Science, asked by BrainlyProgrammer, 2 months ago

<Python Challenge>

Write the one-liner approach for finding the factorial of a number accepting number of terms as input.

Sample Input:-
5
Sample Output:-
Factorial of 5 is 120​

Answers

Answered by anindyaadhikari13
10

Solution:

There is a predefined function factorial(x) present in math module. So, we can easily find out factorial.

import math as m

n=int(input("Enter a number - "))

print(f"Factorial of {n} is {m.factorial(n)}")

But we have to write one liner códe. To do this, we have to import math module at runtime. Here comes the códe -

print("Factorial is:",__import__('math').factorial(int(input("Enter a number - "))))

See the attachment for output.

•••♪

Attachments:
Similar questions