Demo entry 6352350

A453Task1

   

Submitted by anonymous on Mar 24, 2017 at 18:51
Language: Python 3. Code size: 3.1 kB.

#Madeleine Laband - A453 Task 1
###
# Task 1 is to develop a program that analyses a sentence containing several
# words without punctuation. When a word in the sentence is input,
# the program finds all of the places where the word occurs in the sentence. 
###


#splash:
print("**************************************")
print("*      A453 Task 1: Word Finder      *")
print("*         Maddy Laband 7023          *")
print("**************************************")

#Intialise boolean
SentenceIsValid = False         
while SentenceIsValid == False:

    #Get a sentence from user
    print()
    SentenceIn = input("Please enter a sentence: ")
    SentenceIn = SentenceIn.lower()
    
    #Validate
    if SentenceIn == "":        #pressence check
        print("Error, please enter something")
        
    elif SentenceIn == " ":       #pressence check
        print ("Error, please enter a sentence")

    elif "." in SentenceIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif "," in SentenceIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif ";" in SentenceIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif ":" in SentenceIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif "?" in SentenceIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif "!" in SentenceIn:       #punctuation check
        print("Error, please do not enter punctuation")
    else:
        SentenceIsValid = True      #must be valid to get here
        
WordIn = input("Please enter a word to search for: ")
WordIn = WordIn.lower()

WordIsValid = False         #intialise boolean
while WordIsValid == False:

#Validate WordIn
    if WordIn == "":        #pressence check
        print("Error, please enter something")
        
    elif WordIn == " ":       #pressence check
        print ("Error, please enter a word")

    elif "." in WordIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif "," in WordIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif ";" in WordIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif ":" in WordIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif "?" in WordIn:       #punctuation check
        print("Error, please do not enter punctuation")
    elif "!" in WordIn:       #punctuation check
        print("Error, please do not enter punctuation")
    else:
        WordIsValid = True      #must be valid to get here
        
#Split the sentence into each chunk
MyList = (SentenceIn).split()

for item in MyList:
    print (item)

value = (WordIn)

for index in range(len(MyList)):
    Word = MyList[index]
    if Word == value:
        print ("list contains", value, 'at position', index+1)
    
input()     #pauses the program

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).