代码拉取完成,页面将自动刷新
# Script Name : factorial_perm_comp.py
# Author : Ebiwari Williams
# Created : 20th May 2017
# Last Modified :
# Version : 1.0
# Modifications :
# Description : Find Factorial, Permutation and Combination of a Number
def factorial(n):
fact = 1
while n >= 1:
fact = fact * n
n = n - 1
return fact
def permutation(n, r):
return factorial(n) / factorial(n - r)
def combination(n, r):
return permutation(n, r) / factorial(r)
def main():
print('choose between operator 1,2,3')
print('1) Factorial')
print('2) Permutation')
print('3) Combination')
operation = input('\n')
if operation == '1':
print('Factorial Computation\n')
while True:
try:
n = int(input('\n Enter Value for n '))
print('Factorial of {} = {}'.format(n, factorial(n)))
break
except ValueError:
print('Invalid Value')
continue
elif operation == '2':
print('Permutation Computation\n')
while True:
try:
n = int(input('\n Enter Value for n '))
r = int(input('\n Enter Value for r '))
print('Permutation of {}P{} = {}'.format(n, r, permutation(n, r)))
break
except ValueError:
print('Invalid Value')
continue
elif operation == '3':
print('Combination Computation\n')
while True:
try:
n = int(input('\n Enter Value for n '))
r = int(input('\n Enter Value for r '))
print('Combination of {}C{} = {}'.format(n, r, combination(n, r)))
break
except ValueError:
print('Invalid Value')
continue
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。