博客笔记_python笔记哈

心理障碍终于调节好了,希望人人都能很快逃离精神疾病的困扰,加油!祈福!

from math import factorial
输入一个正整数n,对其进行因式分解并输出。
a = int(raw_input(“请输入一个整数:”))
b = ”
d = a
q = 1
print “n = %d”%a
while q:
if a == 1:
break
for i in xrange(2,a+1):
if a == i:
q = 0
break
if a%i == 0:
b += ‘%s *’%i
a = a/i
break
print “%s = %s%s”%(d,b,a)

s = raw_input(“请输入一行字符串:”)
letters = 0
space = 0
digit = 0
other = 0
print len(s)
for i in s:
if i.isalpha():
letters+=1
elif i.isspace():
space+=1
elif i.isdigit():
digit+=1
else:
other+=1

print ‘字母数量为%d, 空格数量为%d, 数字数量为%d, 其他数量为%d’ % (letters, space, digit, other)

Tn = 0
Sn = []
s = ”
a = int(raw_input(“请输入一个数字:”))
n = int(raw_input(“请输入数量:”))
for count in xrange(n):
Tn = Tn + a
a = a * 10
Sn.append(Tn)
s += ‘%s + ’ % str(Tn)

Sn = reduce(lambda x, y: x + y, Sn)
print ‘sum = %s = %d’ % (s[:-2], Sn)

L = [‘b’,’c’,’d’,’c’,’b’,’a’,’a’]
L2 = list(set(L))
L2.sort()
print L2

L = [‘b’,’c’,’d’,’c’,’b’,’a’,’a’]
L2 = []
[L2.append(x) for x in L if x not in L2]
print L2

L1 = [1,3,5,7,9]
L2 = [2,4,6,8]
def Combine(L1,L2,tmp):
if not L1 or not L2:
tmp.extend(L1)
tmp.extend(L2)
return tmp
else:
if L1[0]

猜你喜欢

转载自blog.csdn.net/qq_25213395/article/details/82388162
今日推荐