Commit d177b119 by 安晓东

第二次作业-山峰数组

parent 1ef9125d
import re
class ReadFile():
# 获取文件的信息,切分根据开头数字取出后面对应的信息
def read_file(self, file_num):
with open('../homework_02/answer_info', encoding='utf-8') as f:
s = f.readlines()
for i in s:
h = i.split('.')
if file_num in h[0]:
return '\033[33m%s\033[0m' % h[1]
continue
# 判断是否切分字符串格式化输出
def format_out(self, fie):
try:
if '>' in fie:
file_split = fie.split('>')
file_len = len(file_split)
for i in range(file_len):
s = '\t' + file_split[i] + '\t'
print(s)
else:
print('\t' + fie)
except TypeError:
print("值不存在")
# 换行输出
def for_split(self, file_num,flg=None):
s = self.read_file(file_num).split('>')
if flg is not None:
for i in range(1, len(s) - 1):
print('\t'+s[i])
else:
print(s[0])
# 判断字符中包含的数字
def te(self, f):
j = len(re.findall('\d', f))
print(j)
def test_phone(self, f):
# # li = []
h = re.findall('\d{11}', f)
# print(h)
for s in h:
reg = '^((18[4,7])|(17[1,6])|(13[3,8]))\d{8}$'
u = re.findall(reg, s)
if u:
print(s)
def test_ip(self, ip):
h ='(\d{1,3}.){3}\d{1,3}'
j = re.search(h, ip)[1]
print(j)
# 判断读取一行还是两行同时读取
def get_info(self, yes, num1='', num2=None):
if yes == '2':
return self.format_out(self.read_file(num1) + '\t' + self.read_file(num2))
else:
return self.format_out(self.read_file(num1))
if __name__ == '__main__':
s = ReadFile()
# s.read_file('6')
# s.format_out(s.read_file('6'))
# s.get_info('1', '6')
# s.for_split('6')
# s.for_split('6','1')
# s.te('42197里包含几个数字啊?')
# print(s.test_ip('下边的号码中,哪些是手机号呢:18475309876,18719462345,17665148777,13332839908,12398028761'))
s.test_ip('1324.231.432.1234,192.168.1.6,10.25.11.8这些信息中,哪些是ip呢')
def numJewelsInStones(J, S): def numJewelsInStones(J, S):
count = 0 # count = 0
for i in S: # for i in S:
if i in J: # if i in J:
count+=1 # count+=1
print(count) # print(count)
return sum([i in J for i in S])
numJewelsInStones("aA","aAAbbbb") # 预期输出 3 print(numJewelsInStones("aA", "aAAbbbb")) # 预期输出 3
\ No newline at end of file
1.贪心学院是一家高端重视售后服务,的在线教育培训机构
2.项目式培训
3.贪心学院的项目式培训结合了西方项目式培训的优点和国内的现状,最终变化成以训练营的方式进行。>做项目为主,老师负责解决部分知识的问题,学生负责自学部分知识,和不停的做项目,把知识巩固。>在项目练习中,不仅仅学习到了知识,同时也培养起来良好的学习习惯和解决问题的能力。
4.贪心学院
5.无编程基础,并且想学习编程的同学。
6.人群包含很广泛。>第一:非IT圈内人群,想通过学习转行到编程领域中>第二:已经是IT圈内的,其他语言的开发人员,想学习Python编程>第三:已经是IT圈内的,但是并不是开发人员,如产品、测试、运维、DBA等岗位>第四:学生,未来想从事编程的工作>第五:未来想从事AI领域工作的,可先通过这门课程的学习,打下良好的基础
7.强大的服务体系,我们拥有每天跟学员沟通的良好服务机制。不放弃任何一个学员,只要来了,就一定要让你学会。
\ No newline at end of file
def peakIndexInMountainArray(A):
"""
:type A: List[int]
:rtype: int
"""
# return A.index(max(A))
for i in range(len(A)-1):
if A[i+1] < A[i]:
a_max = A[i]
return A.index(a_max)
print(peakIndexInMountainArray([9, 1, 15, 3])) # 预期输出 1def peakIndexInMountainArray(A):
import re
from homewor_2.read_fiel import ReadFile
class questint_answer():
read = ReadFile()
def qustion_an(self):
# 根据用户的输入,做出对应的回答
while True:
info = input('\033[35m用户>>>\033[0m')
if re.findall('贪心学院是做什么的?|做什么', info):
self.read.get_info('1')
elif re.findall('^贪心|贪心学院', info):
self.read.get_info('2', '1', '2')
elif re.findall('^课程|啥课程', info):
self.read.get_info('2', '2', '5')
elif re.findall('方式|(学院的课程是什么方式进行上课的?)', info):
self.read.get_info(1,'2')
elif re.findall('什么是项目式培训呢?|项目式', info):
self.read.get_info(1,'3')
elif re.findall('人工智能哪家强?|^强', info):
self.read.get_info(1,'4')
elif re.findall('(Python+AI)课程具体更适合哪些人群呢?|更适合哪些人群', info):
self.read.for_split('6')
self.read.for_split('6', '1')
elif re.findall('(Python+AI)适合什么样的同学学习?|Python', info):
self.read.get_info(1,'5')
elif re.findall('优势是什么?|优势', info):
self.read.get_info(1,'7')
elif re.findall('42197393里包含几个数字啊?|\d', info):
self.read.te(info)
elif info == '下边的号码中,哪些是手机号呢:18475309876,18719462345,17665148777,13332839908,12398028761':
j = re.findall('\d{11}', info)
print(j)
# for s in re.findall('\d{11}', info):
# print(type(s))
# reg = '^((18[4,7])|(17[1,6])|(13[3,8]))\d{8}$'
# u = re.findall(reg, s)
# if u:
#
# print(type(s))
elif re.findall('拜拜|再见|bye', info ):
print('\t''再见')
break
else:
print('\t' + '没有查询到任何信息')
if __name__ == '__main__':
s = questint_answer()
s.qustion_an()
import re
# reg = "hellofdsaa4544f@wangscaihello"
# h = re.findall('[a-z]{4}', reg)
# print(h)
io = '1324.231.432.1234,192.168.1.6,10.25.11.8这些信息中,哪些是ip呢'
# ip = 'this is ip:192.168.1.234;192.145.56.788'
j = re.findall(r"^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$", io)
print(j)
# reg = '(\d{1,3}.){3}\d{1,3}'
# h = re.search(reg, ip)[0]
# print(h)
#
# info = 'pytoppppytofdsaf'
# f = re.findall('pyto+?', info)
# print(f)
# f = re.findall('pyto*?', info)
# print(f)
# f = re.findall('pyto??', info)
# print(f)
# s = '下边的号码中,哪些是手机号呢:18475309876,18719462345,17665148777,13332839908,12398028761'
# h = re.findall('\d{11}',s)
# print(h)
# def test(f):
# h = re.findall('\d{11}', f)
# for i in h:
# reg = '^((18[4,7])|(17[1,6])|(13[3,8]))\d{8}$'
# h = re.findall(reg, i)
# if h:
# print('匹配成功')
# print(i)
# else:
# print('匹配失败')
#
#
# test('下边的号码中,哪些是手机号呢:18475309876,18719462345,17665148777,13332839908,12398028761')
# j = '42197393里包含几个数字啊'
# h = len(re.findall('\d', j))
# def test(f):
# j = len(re.findall('\d', f))
# return j
# print(test('42197543543543543里包含几个数字啊'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment