#Open the file sentenceFile = open ("sentenceFile.txt","r") #read the sentence from the file theSentence = sentenceFile.readline() print("sentenceFile=",theSentence) #change my sentence to upper case sentence =theSentence.upper() print("sentence=",sentence) #split my sentence into a list sentenceList = sentence.split() print("sentenceList=",sentenceList) #ask the user for a word userWord =input("give me a word") print("The word you gave is ", userWord) #set wordPostion to 0 wordPostion = 0 #check if word is there if theWord in theList for everyWordInList in theList if everyWordInList == theWord: print ("Position of ", theWord, " = " wordPostion wordPosition += 1 else: print("ERROR - WORD IS NOT THERE") #Close the file sentenceFile.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question