|
|

楼主 |
发表于 2018-3-8 11:53:57
|
显示全部楼层
这是我改进后的代码:
name = open('lianxiti001.txt','r+')
all_information = name.read()
print(all_information)
user1 = input("which do you want to search:")
QUIT = 1
str1 = 'QIUT'
while QUIT == 1:
for i in range(0,10):
line1 = next(name)
if user1 in line1:
print('result :',line1)
else:
user2 = input("wrong input, try another:")
if user2 == str1:
QUIT = 2
print("Search is over")
name.seek(0,0)
结果还是不理想,直接把结果贴出来,大家指点下:
F:\exercise\venv3\Scripts\python.exe "F:/exercise/venv3/python idle/009.py"
校长:137XXXXXXXX
苹果:131XXXXXXXX
菠萝:125XXXXXXXX
橡胶:156XXXXXXXX
凤梨:176XXXXXXXX
香梨:158XXXXXXXX
樱桃:196XXXXXXXX
脐橙:174XXXXXXXX
甘蔗:142XXXXXXXX
西瓜:161XXXXXXXX
which do you want to search:161
Traceback (most recent call last):
File "F:/exercise/venv3/python idle/009.py", line 9, in <module>
line1 = next(name)
StopIteration
Process finished with exit code 1 |
|