def strrange(stop,begin="A",step=1):
# 初始化
list_alphabet = []
str_temp = ""
# 判断输入是否有错误
judge(begin,stop,str_alphabet)
# 判断起始位置
for i in range(len(list_temp)):
count_begin += 1
if list_temp[i] == begin:
break
# 判断结束位置
count_stop = count_begin
for j in range(count_begin,len(list_temp)):
count_stop += 1
if list_temp[i] == stop:
break
# 按照步伐提取字符串
for each_step in range(count_begin,(count_stop),step):
list_alphabet.append(list_temp[each_step])
for each in list_alphabet:
if each.isalpha():
str_temp += each
return str_temp
str_alphabet = input("请输入你想说的话:")
def judge(begin,stop,str_alphabet):
Brk = 1
count_begin = -1
list_temp = []
list_temp_Brk = []
# 字符串中是否含有起始字符或A
while ("A" not in str_alphabet) and (begin not in str_alphabet):
str_alphabet = input("字符串输入有误,请重新输入:")
# 字符串中开始后是否存在终止符
while stop not in str_alphabet:
str_alphabet = input("字符串输入有误,不包含终止符,请重新输入:")
for each_alphabet in str_alphabet:
list_temp.append(each_alphabet)
# 判断起始位置与结束位置
for i in range(len(list_temp)):
count_begin += 1
if list_temp[i] == begin:
break
for j in range(count_begin,len(list_temp)):
list_temp_Brk.append(list_temp[j])
while stop not in list_temp_Brk:
stop = input("终止符输入错误,请重新输入:")
return stop,list_temp,count_begin
第2个问题的代码!!!! |