qberik

Untitled

Nov 17th, 2022
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1.  
  2. from abc import ABC, abstractclassmethod
  3.  
  4.  
  5. class Calculator(ABC):
  6.  
  7. @abstractclassmethod
  8. def compute(self):
  9. pass
  10.  
  11. class Factorial( Calculator ):
  12. def compute(self,n):
  13. num = 1
  14. while n >= 1:
  15. num = num * n
  16. n = n - 1
  17. return num
  18.  
  19.  
  20.  
  21.  
  22. n = float(input("Enter n "))
  23.  
  24. f = Factorial()
  25.  
  26. print( "n! =", f.compute( n ) )
  27. print( "n!! =", f.compute( f.compute( n ) ) )
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment