匿名用户
1级
2012-06-08 回答
#!/user/bin/python
def test():
while(True):
flag=0
#python 2.7
value=raw_input("Enter value:")
#python 3.2
#value=input("Enter value:")
print(value)
f1=open(r"c:\b.txt",'r').readlines()
#delete '\n' at the end of line
f1=list(map(lambda x:x.strip(),f1))
#check out the data in b.txt
print(f1)
for member in f1:
if(value in member):
print("find it!")
flag=1
break
if(flag==0):
print("Not find it, and you are free now!")
break
test()
追问:
不好意思 没把问题写清楚,你的代码我试了,要完全匹配才能判断是不是存在。
追答:
#!/user/bin/python
import sys
def test():
while(True):
flag=0
if (sys.version
#python version less than 3.0.0
value=raw_input("Enter value:")
print("this is "+sys.version)
else:
#python version greater than 3.0.0
value=input("Enter value:")
print("this is 3.0+")
f1=open(r"c:\b.txt",'r').readlines()
#delete '\n' at the end of line
f1=list(map(lambda x:x.strip(),f1))
#check out the data in b.txt
print(f1)
for member in f1:
if(value in member):
print("find it!")
flag=1
break
if(flag==0):
print("Not find it, and you are free now!")
break
test()
追问:
测试正确 谢谢你的帮助