I've got this code:
Text = input("Copy Text here ")
WordList = Text.split(" ")
i = 0
for i in range (0, len(WordList)-1):
i += 1
while (i <= len(WordList)) :
if (WordList[i] == "Name" or "Name1" or "Name2") :
print(WordList[i])
else:
print("No DATA")
If I run this code I get two problems: first it only prints the last entry which might be because I forgot to tell it to stop counting when "Name", "Name2" or "Name1" is found. The bigger problem is that this ends in an infinite loop and I've got no idea why.
text = input("Copy Text here ")
wordlist = text.split(" ")
for i in wordlist:
if (i in ["Name", "Name1", "Name2"]):
print (i)
else:
print ("No DATA")
You are over complicating the things the python handles the iterations very nicely, you dont need to increment the counter after ever iteration , Actually you don't need any sort of counter.