patternpythonMinor
Representation of the formula P(n) = (n!)(6^n)
Viewed 0 times
representationtheformula
Problem
I'm trying to represent the following mathematical expression in Python:
$$P(n) = (n!)(6^n)$$
The program should compute the answer to expression when
Is there any way that I could improve the code? (I'm fairly new to programming):
$$P(n) = (n!)(6^n)$$
The program should compute the answer to expression when
n = 156. I have attempted to create the program in python and it produces the correct answer (when compared with wolfram alpha's answer). The answer is approximately \$10^{397}\$.Is there any way that I could improve the code? (I'm fairly new to programming):
import math
n=156
F = math.factorial(n)
pwr = pow(6,n)
P = F*pwr
print PSolution
No reason not to make this into a function so it accepts any
Usage:
n.from math import factorial
def p_of_n(n):
return factorial(n) * 6**nUsage:
p_of_n(156)
# output
# 18406764427683965418916585176958885211344286062729194034218082474442355263185795072343804159971536825774135674029142847535155218179997173513194885826708904869034790974161877000771825382336273724208349735310762691458714078255765145189212114617969848727557053656769497332473231995332585780414682079382672173143342192602090273021078801460026695582968493824697958400000000000000000000000000000000000000Code Snippets
from math import factorial
def p_of_n(n):
return factorial(n) * 6**np_of_n(156)
# output
# 18406764427683965418916585176958885211344286062729194034218082474442355263185795072343804159971536825774135674029142847535155218179997173513194885826708904869034790974161877000771825382336273724208349735310762691458714078255765145189212114617969848727557053656769497332473231995332585780414682079382672173143342192602090273021078801460026695582968493824697958400000000000000000000000000000000000000Context
StackExchange Code Review Q#71361, answer score: 4
Revisions (0)
No revisions yet.