Computer Science, asked by manandhall480, 9 months ago

Write python code to input a number and calculate factorial of a number. For example if number is 5 then factorial will be 5x4x3x2x1 = 120.

Answers

Answered by Anonymous
11

Codes :

\tt{\red{ \# \: Python \: is \: Best}} \\ \tt{num\ =\ \purple{int} ( \purple{i nput} (\green{"Enter \: a \: number"} )) } \\ \tt{fact\ =\ 1} \\ \tt{\orange{for} \:  i \: \orange{in} \: \purple{range} \: (num) \: :} \\ \; .\; \;\; \; \; \;  \tt{fact \: = \: fact \: * \: (i \: + \: 1)} \\  \tt{\purple{print} \: ( \green{" Factorial \: of \: "} \: , \: num \: , \: \green{" \: = \: "} \: , \: fact)}

_______________________

Output :

\tt{\blue{Enter \: a \: number \: } : \: 5} \\ \tt{\blue{Factorial \: of \: 5 \: = \: 120}}

_______________________________

Additional Information :

• Python is a high level, dynamic, Object-Oriented programming language.

• Python was developed by Guido Van Rossum in 1991 , in Netherlands.

Features of Python are :

  • Simple and easy.
  • Free/Open Source.
  • High-level language.
  • Portable.
  • Extensible and Embedded.
  • Standard Library.
Answered by nsprabha
2

Answer:

def fact(n):

   if n==1:

       return 1

   else:

       return n*fact(n-1)

n=int(input("enter a number"))

print(fact(n))

Similar questions