Fourteenth title

topic

The decomposition of the quality factor of a positive integer. For example: the input 90, to print out 90 = 2 . 3 3 * 5.

my_code:

def fact(num):
    a = []
    if num == 1:
        a = [1];
        return a
    else:
        while num != 1:
            for i in range(2,num+1):
                if num % i == 0:
                    a.append(i)
                    num = num // i
                    break
        return a
 

for j in range(1,101):
    print('%i = '%j,end='')
    a = fact(j)            
    for i in range(0,len(a)):
        print('%i '%a[i],end='');
        if i!= len(a)-1:
            print('x ',end='')
    print('\n')

Guess you like

Origin www.cnblogs.com/lovely-bones/p/11627115.html