小小的Python编程题,求大神解决
2个回答
展开全部
# -*- coding:utf-8 -*-
def isprime(num):
count = num / 2
while count >1:
if num % count == 0:
return False
break
else:
count -= 1
else:
return True
def getfactor(num):
l = []
if isprime(num):
return [num]
count = num / 2
for n in range(2, count + 1):
if num % n == 0 and isprime(n):
l.append(n)
return l
def suyinzi(num):
fac = getfactor(num)
mul = 1
for n in fac:
mul *= n
if mul == num:
return fac
else:
return fac + suyinzi(num / mul)
num=int(raw_input('Please input a number:\r\n'))
print sorted(suyinzi(num))
>>>Please input a number:
120
[2, 2, 2, 3, 5]
追问
不知道对不对,不过谢了
展开全部
def revertint(input):
if input<0:
flag='-'
else:
flag=''
input=str(abs(input))
input=input[::-1]
length =len(input)
for i in range(0,length-1):
if input[0] != '0':
break
input =input[1:]
input =flag + input
return int(input)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询