PYTHON   30

binomial1

Guest on 13th August 2022 07:54:59 AM

  1. m = int(input("Digite m: "))
  2. n = int(input("Digite n: "))
  3.  
  4. # calcule m!
  5. m_fat = 1
  6. i = 2
  7. while i <= m:
  8.     m_fat *= i
  9.     i += 1
  10.  
  11. # calcule m!
  12. n_fat = 1
  13. i = 2
  14. while i <= n:
  15.     n_fat *= i
  16.     i += 1
  17.  
  18. # calcule m-n!
  19. mn_fat = 1
  20. i = 2
  21. while i <= m-n:
  22.     mn_fat *= i
  23.     i += 1
  24.  
  25. binomial = m_fat//(n_fat * mn_fat)
  26.  
  27. print(f"binomial({m}, {n}) = {binomial}")

Raw Paste


Login or Register to edit or fork this paste. It's free.