题目十三:将一个正整数分解质因数。例如:输入60,打印出60=2*2*3*5。
#!/usr/bin/env python3
# -*- coding: utf-8 -*- """ 题目十三:将一个正整数分解质因数。例如:输入60,打印出60=2*2*3*5。""" __author__ = 'Fan Lijun' def fenjie(number):
lst = []
for i in range(2, number):
while number % i == 0:
lst.append(i)
number = number /i
if number > 2:
fenjie(int(number))
return lst def print_list(input_number, lst):
s = input_number
s = s + '='
for m in lst:
s += (str(m) + '*')
print(s[:-1]) if __name__ == '__main__':
input_number = input('请输入一个整数:')
ls = fenjie(int(input_number))
print_list(input_number, ls)