|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1、第一次满足条件了,又想调试一下,调试最后出现了错误,都不知道哪里错了:
代码:
- def strrange(stop,begin="A",step=1):
- # 初始化
- list_temp = []
- list_alphabet = []
- str_temp = ""
- count_begin = -1
- global str_alphabet
- # 字符串中是否含有起始字符或A
- while ("A" not in str_alphabet) and (begin not in str_alphabet):
- str_alphabet = input("字符串输入有误,请重新输入:")
- # 字符串中开始后是否存在终止符
- while stop not in str_alphabet:
- stop = 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
-
- # 判断结束位置
- count_stop = count_begin-1
- 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("请输入你想说的话:")
-
复制代码
问题是:
请输入你想说的话:Afklguberhiopkl'
>>> strrange("i")
'Afklguberhiopkl'
>>>
提取不出来,哭了!
2、这是最初调试的,想调用外部函数内部内容,忘了不知道怎么办?
代码:
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
问题:
>>> strrange("u")
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
strrange("u")
File "C:\python\3.其他\每日练习\204strrange.py", line 11, in strrange
for i in range(len(list_temp)):
NameError: name 'list_temp' is not defined
各位大哥帮下忙!!!!!
|
|