Menu Bar

Horizontal Scrollable Menu

ads

Search This Blog

Factorial number in python with algorithm

Q) : Implement python script to print factorial of number .


Aim: To print factorial number 

Algorithm: 

step 1; Start
step 2; Declare the variable n and read n value 
step 3: Initialise fact = 1 and i = 1
step 4: In while loop perform 
          fact = fact * i
          i = i + 1
step 5: print factorial of n
step 6: end

Source Code:

n = int(input('enter the number :'))
fact1 = 1

i = 1
while n >= i:
    fact2 = fact1 * i
    i = i + 1
    print(f"factorial number of n is {fact2}")

Input:
enter the number: 50

Outout:

enter the number :50
factorial number of n is 1
factorial number of n is 2
factorial number of n is 3
factorial number of n is 4
factorial number of n is 5
factorial number of n is 6
factorial number of n is 7
factorial number of n is 8
factorial number of n is 9
factorial number of n is 10
factorial number of n is 11
factorial number of n is 12
factorial number of n is 13
factorial number of n is 14
factorial number of n is 15
factorial number of n is 16
factorial number of n is 17
factorial number of n is 18
factorial number of n is 19
factorial number of n is 20
factorial number of n is 21
factorial number of n is 22
factorial number of n is 23
factorial number of n is 24
factorial number of n is 25
factorial number of n is 26
factorial number of n is 27
factorial number of n is 28
factorial number of n is 29
factorial number of n is 30
factorial number of n is 31
factorial number of n is 32
factorial number of n is 33
factorial number of n is 34
factorial number of n is 35
factorial number of n is 36
factorial number of n is 37
factorial number of n is 38
factorial number of n is 39
factorial number of n is 40
factorial number of n is 41
factorial number of n is 42
factorial number of n is 43
factorial number of n is 44
factorial number of n is 45
factorial number of n is 46
factorial number of n is 47
factorial number of n is 48
factorial number of n is 49
factorial number of n is 50

Process finished with exit code 0

No comments:

ads3