代码改成这样吧# 代码如下
def duanchufa(a):
#print(f'传入参数{a}')
i = 2
for c in range(0, a):
if a % i == 0:
return i
else:
i += 1
def run(shuru):
yinshujihe = []
for i in range(1, shuru):
if shuru>1:
yinshu = duanchufa(shuru)
#print(f'因素 {yinshu}')
shuru = shuru // yinshu
yinshujihe.extend([yinshu])
return yinshujihe
shuru = input('输入一个要分解的因数')
shuru = int(shuru)
yinshujihe = run(shuru)
#print(yinshujihe)
if len(yinshujihe) < 2:
print('该数为素数')
else:
p=f'{shuru} = {yinshujihe[0]}'
for num in yinshujihe[1:]:
p=p+f' * {num}'
print(p)
|