主要内容
- Python基础练习题
一.Python基础练习题
1.密码验证合格程序
代码如下(示例):
def check(s):if len(s) <= 8:return 0a, b, c, d = 0, 0, 0, 0for item in s:if ord('a') <= ord(item) <= ord('z'):a = 1elif ord('A') <= ord(item) <= ord('Z'):b = 1elif ord('0') <= ord(item) <= ord('9'):c = 1else:d = 1if a + b + c + d < 3:return 0for i in range(len(s)-3):if len(s.split(s[i:i+3])) >= 3:return 0return 1while 1:try:print('OK' if check(input()) else 'NG')except:break
2.两数之和
代码如下(示例):
class Solution:def twoSum(self,numbers,target):for i in range(len(numbers)-1):for j in range(i+1,len(numbers)):if (numbers[i]+numbers[j]==target:return [i+1,j+1]
3.字符个数统计
代码如下(示例):
import syswhile True:try:str=''.join(set(input()))count=0for i in str:if 0<=ord(i)<=127:count+=1print(count)except:break
总结
以上是今天要讲的内容,练习了一些python题。