1.

Write a program to find the factorial of a number in python​

Answer»

Answer:

The given códe is written in Python 3.

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

F=1

for i in range(2,n+1):

f=f * i

print("Factorial:",f)

LOGIC:

  • Enter the number, say n.
  • INITIALISE f = 1
  • Loop through numbers in the range - 2 to n.
  • Multiply f with each numbers in the range.
  • RESULT obtained after termination of loop equal to the factorial of the number.
  • Display the factorial.

See the ATTACHMENT for output.

•••♪



Discussion

No Comment Found