核武器
发表于 2018-3-11 21:15:05
def jiecheng(n):
m = ''
jie = 1
for i in range(1,n+1):
jie = jie*i
m = m+str(jie)
return m
def shuchu(m):
b = 0
while b<=(len(m)/40):
a = '('+str(b)+')'
a = a.ljust(6)
print(a,end = '')
for i in m:
print(i,end='')
print()
b += 1
n = int(input('输入整数:'))
shuchu(jiecheng(n))
晓屁屁
发表于 2018-3-11 21:24:04
count = 1
str1 = ''
count1 = 0
count2 = 1
dict1 = dict()
for i in range(1,51):
count *= i
str1 += str(count)
print('( %d)'%count2,end=' ')
for x in range(len(str1)):
count1 += 1
print(str1,end='')
if count1 == 40:
count2 += 1
print('\n'+'( %d)'%count2,end=' ')
count1 = 0
t6am3
发表于 2018-3-11 21:28:02
def fact(n):
if 0 == n:
return 1
else:
return n*fact(n-1)
str_tmp = ''
for i in range(1, 51):
str_tmp += str(fact(i))
j = 1
count = 0
for i in range(len(str_tmp)):
if count == 0:
print('(%2d)'%j, end='')
print(str_tmp, end='')
count += 1
if count == 40:
print('')
j += 1
count = 0
wyp02033
发表于 2018-3-11 21:36:47
def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n-1)
def main():
num_str = ''
for i in range(1, 51):
num_str += str(factorial(i))
print("(1)", end='')
for i in range(len(num_str)):
if i != 0 and i % 40:
print(num_str,end='')
else:
if i != 0:
print()
print("(%d)" % (i//40+1), end='')
print(num_str, end='')
print()
if __name__ == '__main__':
main()
纳兰小寒
发表于 2018-3-11 22:35:44
本帖最后由 纳兰小寒 于 2018-3-11 22:48 编辑
def fun(n):
if n == 1:
return 1
else:
return fun(n-1) * n
def list_sort():
num_str =''
for x in range(1,51):
num_str += str(fun(x))
index = 0
count = 1
while index < len(num_str):
print('({:>2}) {}'.format((count),num_str))
count += 1
index += 40
list_sort()
inverseli
发表于 2018-3-11 22:40:33
import sys
sys.setrecursionlimit(100000)#修改递归深度
numbers = []
def jiecheng(n):
if n == 1:
return 1
else:
return n * jiecheng(n-1)
for i in range(1,51):
result = jiecheng(i)
numbers.append(str(result))
str1 = ''.join(numbers)#获得字符串
book = 40 #一个标记
for i in range(50):
print('('+str(i+1)+')',end=' ')
print(str1)
if len(str1) < 40:
sys.exit()
fengyutianshang
发表于 2018-3-11 22:46:05
def factorial(num):
"计算num的阶乘"
fac = 1
if num < 0:
return 0
elif num == 0:
return 1
else:
for i in range(1, num + 1):
fac = fac * i
return fac
tem = ""
for each in range(1,51):
tem = tem + str(factorial(num = each))
t = 1
while len(tem) >= 40:
if t < 10:
xu = "( "+ str(t) + ") "
else:
xu = "("+ str(t) + ") "
print( xu + tem)
tem = tem
t += 1
print( "("+ str(t) + ") " + tem)
( 1) 1262412072050404032036288036288003991680
( 2) 0479001600622702080087178291200130767436
( 3) 8000209227898880003556874280960006402373
( 4) 7057280001216451004088320002432902008176
( 5) 6400005109094217170944000011240007277776
( 6) 0768000025852016738884976640000620448401
( 7) 7332394393600001551121004333098598400000
( 8) 0403291461126605635584000000108888694504
( 9) 1835216076800000030488834461171386050150
(10) 4000000884176199373970195454361600000026
(11) 5252859812191058636308480000000822283865
(12) 4177922817725562880000000263130836933693
(13) 5301672180121600000008683317618811886495
(14) 5181944012800000002952327990396041408476
(15) 1860964352000000010333147966386144929666
(16) 6513375232000000003719933267899012174679
(17) 9944815083520000000013763753091226345046
(18) 3159795815809024000000005230226174666011
(19) 1176000722410007429120000000020397882081
(20) 1974433586402817399028973568000000008159
(21) 1528324789773434561126959611589427200000
(22) 0000334525266131638071081700620534407516
(23) 6515200000000014050061177528798985431426
(24) 0624451156993638400000000060415263063373
(25) 8356373551320685139975072645120000000002
(26) 6582715747884487680436258110146158903196
(27) 3852800000000011962222086548019456196316
(28) 1495657715064383733760000000000550262215
(29) 9812088949850305428800254892961651752960
(30) 0000000002586232415111681806429643551536
(31) 1197996919763238912000000000012413915592
(32) 5360726708622890473733750385214863546777
(33) 6000000000060828186403426756087225216332
(34) 1295376887552831379210240000000000304140
(35) 9320171337804361260816606476884437764156
(36) 8960512000000000000
fc1735
发表于 2018-3-11 23:20:23
def q162():
line=i=ans=1
string=''
while i<=50:
ans*=i
string+=str(ans)
i+=1
while string:
print('(%2d)'%(line),string[:40])
string=string
line+=1
Blackwong
发表于 2018-3-11 23:22:16
def fac(n):
s = 1
for i in range(1,n+1):
s = i*s
return s
#main
out = ""
for i in range(1,51):
result = fac(i)
out = out + str(result)
hang = int(len(out) / 40)
for i in range(1,hang+1):
print('(%2d)'%i,out)
print('(%2d)'%(hang+1),out)
一开始看感觉好简单,但是做了40分钟才勉强实现功能。。。。
o41003121
发表于 2018-3-11 23:49:55
def factorial(x):
facsum = 1
temp = x
while temp > 0:
facsum *= temp
temp -= 1
return str(facsum)
result = ''
for i in range(1,51):
result += factorial(i)
lines = len(result) // 40 + 1
for each in range(lines):
print('(%2d)' % (each + 1),' ',result)
qwc3000
发表于 2018-3-12 08:24:21
def fun(n):
if n==1:
return 1
return n*fun(n-1)
str_num=''
hang_num=1
for i in range(1,51):
str_num+=str(fun(i))
while len(str_num)>=40: #判断长度是否超过40
result=str_num
str_num=str_num
print('(%d) %s' %(hang_num,result),end='\r\n')#打印输出
hang_num+=1
print('(%d) %s' %(hang_num,str_num),end='\r\n')
天圆突破
发表于 2018-3-12 09:35:20
本帖最后由 天圆突破 于 2018-3-12 11:03 编辑
def sprint(string):
lst = list()
i = 0
n = len(string)
while i < n:
lst.append(string)
i += 40
else:
for i, each in enumerate(lst, 1):
print('%.2d%s'%(i, each))
def nn(n = 50):
string = '1'
for j in range(1, n+1):
p = 1
for i in range(1, j+1):
p *= i
string += str(p)
return string
if __name__=='__main__':
sprint(nn(50))
tsembrace
发表于 2018-3-12 09:52:16
'''
我们知道1的阶乘是1,2的阶乘是2,3的阶乘是6,4的阶乘是24,将前4个数字的阶乘排在一起是12624
现在要求将1~50的阶乘排在一起打印出来
要求,每40个数字1行,当本行超过40个时换行到下一行,另外在每行的开头打印行号。
'''
#生成所有阶乘结果连接起来数值字符串的函数
def create_Numstr(n):
def jc(m):
if m==0:
return 1
else:
return m*jc(m-1)
stra=''
for i in range(1,n+1):
stra=stra+str(jc(i))
return stra
#生成该字符串对应每40个字符一组元素的列表
def print_40perrow(n):
#首先生成1~n阶乘结果连接起来的字符串
xstr=create_Numstr(n)
lenx=len(xstr)
i=0
while i<lenx:
xh=i//40+1
print("(%2d)"% (xh)+''+xstr)
i=i+40
print_40perrow(50)
lovesword
发表于 2018-3-12 10:22:25
import math
a = reduce(lambda x, y: x + y, )
b = for i in xrange(0, len(a), 40)]
c = ''.join(map(lambda x: '(%s) %s\n' % (x + 1, x), enumerate(b)))
print c
nanayuri
发表于 2018-3-12 10:40:57
def factorial(n):
total = 1
for i in range(1, n + 1):
total *= i
return str(total)
total_str = ''
for num in range(1, 51):
total_str += factorial(num)
len_str = len(total_str)
row_num = len_str // 40 + 1
for each_row in range(1, row_num + 1):
str_final = total_str
print('(' + ('%2s' % str(each_row)) + ')' + str_final)
nononoyes
发表于 2018-3-12 11:24:45
#定义一个方法求阶乘
def fun(num):
factorial = 1
for i in range(1, num + 1):
factorial = factorial * i
return factorial
str1 = ''
for i in range(1,51):
str1 = str1 + str(fun(i))
row = len(str1)//40
if(len(str1)%40!=0):
row +=1
for i in range(row):
print('(%d) '%(i+1),end = '\t')
print(str1)
(1) 1262412072050404032036288036288003991680
(2) 0479001600622702080087178291200130767436
(3) 8000209227898880003556874280960006402373
(4) 7057280001216451004088320002432902008176
(5) 6400005109094217170944000011240007277776
(6) 0768000025852016738884976640000620448401
(7) 7332394393600001551121004333098598400000
(8) 0403291461126605635584000000108888694504
(9) 1835216076800000030488834461171386050150
(10) 4000000884176199373970195454361600000026
(11) 5252859812191058636308480000000822283865
(12) 4177922817725562880000000263130836933693
(13) 5301672180121600000008683317618811886495
(14) 5181944012800000002952327990396041408476
(15) 1860964352000000010333147966386144929666
(16) 6513375232000000003719933267899012174679
(17) 9944815083520000000013763753091226345046
(18) 3159795815809024000000005230226174666011
(19) 1176000722410007429120000000020397882081
(20) 1974433586402817399028973568000000008159
(21) 1528324789773434561126959611589427200000
(22) 0000334525266131638071081700620534407516
(23) 6515200000000014050061177528798985431426
(24) 0624451156993638400000000060415263063373
(25) 8356373551320685139975072645120000000002
(26) 6582715747884487680436258110146158903196
(27) 3852800000000011962222086548019456196316
(28) 1495657715064383733760000000000550262215
(29) 9812088949850305428800254892961651752960
(30) 0000000002586232415111681806429643551536
(31) 1197996919763238912000000000012413915592
(32) 5360726708622890473733750385214863546777
(33) 6000000000060828186403426756087225216332
(34) 1295376887552831379210240000000000304140
(35) 9320171337804361260816606476884437764156
(36) 8960512000000000000
帝企鹅kx
发表于 2018-3-12 12:37:59
def jiesheng(n):
if n<1:
print('输入有误')
else:
x=1
y=1
string=''
while n>y:
x=x*y
y=y+1
string=string+str(x)
x=x*n
string=string+str(x)
return string
n=int(input('请输入一个整数:'))
hj=jiesheng(n)
a=0
b=40
c=1
pri=''
while a<len(hj):
pri=hj
print('('+str(c)+')'+pri)
a+=40
b+=40
c+=1
Chase_Kas
发表于 2018-3-12 13:45:28
本帖最后由 Chase_Kas 于 2018-3-12 17:21 编辑
def factorial(a):
product = 1
if a == 0:
return 1
else:
for i in range(1, a + 1):
product *= i
return product
def fun(i):
str1 = ''
for i in range(1, i+1):
str1 += str(factorial(i))
if not len(str1) % 40:
num_line = len(str1)//40 + 1
else:
num_line = len(str1)//40 + 2
for j in range(1, num_line):
line = '(' + str(j).rjust(len(str(num_line))) + ')'
print(line, '', str1[((j-1) * 40):(j * 40)])
fun(50)
graceasyi
发表于 2018-3-12 16:01:23
from functools import reduce
def fact(n):
if n == 0:
return 1
else:
return reduce(lambda x, y: x*y, range(1, n+1)) # 求阶乘
str1 = ''
for i in range(1, 51):
str1 += str(fact(i))
for k in range(0, len(str1), 40):
print("(%2d)" % (k // 40 + 1), end=' ')
print(str1)
结果:
( 1) 1262412072050404032036288036288003991680
( 2) 0479001600622702080087178291200130767436
( 3) 8000209227898880003556874280960006402373
( 4) 7057280001216451004088320002432902008176
( 5) 6400005109094217170944000011240007277776
( 6) 0768000025852016738884976640000620448401
( 7) 7332394393600001551121004333098598400000
( 8) 0403291461126605635584000000108888694504
( 9) 1835216076800000030488834461171386050150
(10) 4000000884176199373970195454361600000026
(11) 5252859812191058636308480000000822283865
(12) 4177922817725562880000000263130836933693
(13) 5301672180121600000008683317618811886495
(14) 5181944012800000002952327990396041408476
(15) 1860964352000000010333147966386144929666
(16) 6513375232000000003719933267899012174679
(17) 9944815083520000000013763753091226345046
(18) 3159795815809024000000005230226174666011
(19) 1176000722410007429120000000020397882081
(20) 1974433586402817399028973568000000008159
(21) 1528324789773434561126959611589427200000
(22) 0000334525266131638071081700620534407516
(23) 6515200000000014050061177528798985431426
(24) 0624451156993638400000000060415263063373
(25) 8356373551320685139975072645120000000002
(26) 6582715747884487680436258110146158903196
(27) 3852800000000011962222086548019456196316
(28) 1495657715064383733760000000000550262215
(29) 9812088949850305428800254892961651752960
(30) 0000000002586232415111681806429643551536
(31) 1197996919763238912000000000012413915592
(32) 5360726708622890473733750385214863546777
(33) 6000000000060828186403426756087225216332
(34) 1295376887552831379210240000000000304140
(35) 9320171337804361260816606476884437764156
(36) 8960512000000000000
guobingjie123
发表于 2018-3-12 16:17:20
result=""
fori inrange(1,51):
total=1
forj inrange(1,i+1):
total*=j
result=result+str(total)
if len(result)==40:
print(result)
eliflen(result)>40:
print(result[:40])
result=result
else:
if i==50:
print(result)