# python 练习三

(2017-网易-笔试编程题)-字符串练习

1.单词每个字母都是大写字母
2.单词没有连续相等的字母
3.单词没有形如“xyxy”(这里的x，y指的都是字母，并且可以相同)这样的子序列，子序列可能不连续。

AAA

Dislikes

#!/usr/bin/env python
#coding:utf-8
"""
file:.py
date:2017/8/31 9:12
author:peak
description:
"""
def Judge1(Word):
if Lenth == 1:
return True
else:
for n in range(Lenth-1):
if Word[n] == Word[n+1]:
return False
else :
return True
def Judge2(Word):
L = list(Word)
for i in L :
if L.count("i") == 1 :
L.remove("i")
Ls = []
for i in range(0,len(L)-1):
for j in range(i+1,len(L)):
Ls.append(L[i]+L[j])
if len(Ls) == len(set(Ls)):
return True
else:
return False
Word = raw_input("输入为一个字符串，都由大写字母组成，长度小于100 : ")
Word=Word.upper()
Lenth = len(Word)
if Lenth >= 100 :
print "it is longer than 100"
if Judge1(Word) and Judge2(Word) :
print "Likes"
else :
print "Dislikes"

(2017-腾讯-在线编程题)

10

2

#!/usr/bin/env python
#coding:utf-8
"""
file:.py
date:2017/8/31 10:16
author:peak
description:
"""
from math import sqrt
Allprime=[]
count = 0
def prime(n):
for i in range(2,n):
flg=True
for j in range(2,int(sqrt(i)+1)):
if i%j==0 :
flg=False
if flg==True :
Allprime.append(i)
n=input("输入包括一个整数n,(3 ≤ n < 1000) : ")
prime(n)
Max=Allprime[-1]
for i in Allprime:
for j in range(i,Max):
if i+j == n:
print "{} + {} = {}".format(i,j,n)
count +=1
print count

(2017-好未来-笔试编程题)–列表练习

They are students.
aeiou

Thy r stdnts.

#!/usr/bin/env python
#coding:utf-8
"""
file:.py
date:2017/9/1 14:12
author:peak
description:
"""
Str1=raw_input("please input a string : ")
Str2=raw_input("please input a string that you want to delete :")
Str=''
for i in Str1 :
if i not in Str2 :
Str += i
print Str

(2017-好未来-在线编程题)

5 5

1 4
2 3
5

(2017-去哪儿网-在线编程)

18位身份证的编码规则是：

5021
502104 198803
5021041988033084
502104198803308324

5021
502104 198803
502104 19880330 84
502104 19880330 8324

#!/usr/bin/env python
#coding:utf-8
"""
file:.py
date:2017/9/1 15:46
author:peak
description:
"""
while True :
Id=raw_input("please input the id number : " )
if len(Id) <= 6 :
print Id[0:]
elif 6 print Id[0:6],Id[6:]
elif 14 printId[0:6],Id[6:14],Id[14:]
else:
print "please input right id number!"