Demo entry 5504207

first try at validation

   

Submitted by anonymous on Jun 28, 2016 at 17:30
Language: Python 3. Code size: 1.6 kB.

#controlled assessment practices
#validation tries
#plus sentence_.splt(' ') attempts


sentence_in= input ("please enter a sentence:      ")
#validate:
#presence check attempt
#the code should output an error message if the user hasn't inputted anything
#or has just inputted a blank space(has just hit the space bar)

#length of sentence atttempt
#should check if there are more than two words in the user input
#if not should output an error message

#use this as part of my validation
#for when there should be more than 2 words in a sentence
#this counts white spaces so use it make sure there is more than 2 whites spaces
#if not output error message

##print(sentence_in.count(' '))

#punctuation attempt
#the code should output error message if the user input has any punctuation in it
punctuation = ['!' , ' " ' , ';' , ':' , '.' , '?', '$' , '%' , '(' , ')' , '@', '&', '=']
#list of punctuation that if found in user sentence would reslt in an error message 


for punct_chr in punctuation:        # loop
    if sentence_in.find(punct_chr)>-1:    # condition
        print('Error found %c' %punct_chr)
        print("PLEASE ENTER ANOTHER SENTENCE WIHTOUT ANY PUNCTUATION")   #error message output 
quit 
#NEED TO FIND A WAY TO MAKE THE CODE QUIT WHEN OUTPUTTING AN ERROR MESSAGE, TO STOP THE REST OF THE CODE

print()
print(sentence_in.upper())
print()
list_of_words = (sentence_in.split(' '))
print (list_of_words)


word_to_find= input ("please enter a word you want the position of:      ")

#validate:





print()
print(word_to_find.upper())
print()

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).