Demo entry 6235254

controlled assesment

   

Submitted by anonymous on Oct 13, 2016 at 16:14
Language: Python 3. Code size: 2.2 kB.

#Rachel McKie 7028  28/06/2016
#A453 TASK 1
# - Word Finder within a sentence given by user.
#This task is for us to find a word in a sentence containing multiple word without punctuation.
#When the user inputs a sentence the code should log all the words and there position in the sentence.
#The code doesn’t need to identify case as it doesn’t matter, FOOD, Food, food should be identified as the same word.
print("***********************")
print("**       A453        **")
print("***   Word Finder   ***")
print("*Controlled Assesment *")
print("**   Rachel McKie    **")
print("***********************")

#get inputs:



#validate
is_valid== False

if (sentence_in==" ") or (sentence_in== " "):  #then it will fail the presence check
    print("ERROR: please enter a sentence:  ")  #outputting the error message to get a new user input
    sentence_in= input ("please enter a sentence: ")
    print()
    is_valid= True





#user sentence to which will be used throughout the program


sentence_inU= sentence_in.upper()     #converting sentence_in to upper case

print(sentence_inU)  #outputting new variable

print()
#splitting the user sentence input into a list
list_of_words = (sentence_inU.split( )) #split on a white space
print(list_of_words)     #outputting the list 
print()
print()

#need a word to find within the sentece the user has entered:
word_to_find= input ("please enter a word to find with in the sentence you have entered: ")
word_to_find= word_to_find.upper()     #converting word_to_find to upper case

print()
found_a_match= False    ##boolean to detect a match when found
for indx in range(len(list_of_words)):

    word_in_sentence=list_of_words[indx]   #get a word from th sentence
    if word_in_sentence == word_to_find:
        print("found %s at position %i" %(word_to_find,indx+1))
        found_a_match = True     #got at least one match
   
#all searching done
if not found_a_match:
        print("error: %s not found" %word_to_find)

print ("****finished****") 
    
 



    














input()   #pause for any key for test purposes

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).