# Tutorial_1_Problem_4.py # # Problem Statement: Write a complete Python program that figures out how many upper case letters # appear in a sentence. For the purpose of this program, we define a sentence to be a sequence of # two or more words separated by one blank space (or white space) character and a word to be a # sequence of one or more letters. # # Here are four sample runs: # • If the sentence is "ThE SKy Is BluE.", our program prints "ThE SKy Is BluE. contains 7 upper case letter(s)." on the computer monitor screen. # • If the sentence is "YeLlOw bAnAnA", our program prints "YeLlOw bAnAnA contains 6 upper case letter(s)." on the computer monitor screen. # • If the sentence is "" (i.e., an empty string), our program prints "This is not a sentence." on the computer monitor screen. # • If the sentence is "baNana", our program prints "This is not a sentence." on the computer monitor screen. # # Note: You can assume that the user is “well-behaved”, i.e., s/he will enter only the three categories of test data mentioned in the four sample runs above, namely a valid sentence (sample runs 1. and 2.), an empty sentence (a sentence containing no words – sample run 3.) and a sentence containing one word (sample run 4.). # #If you find it useful to start by designing an algorithm, feel free to do so. # # Anne Lavergne # 2016 # Remember the number of upper case letters countCap = 0 # Get a sentence from user sentence = input("""Please, enter a sentence containing 2 or more words separated by one blank space (or white space) character (a word is 1 or more letters) : """) # Checking for empty sentence and sentence with 1 word, i.e., sentence that does not contain the " " char. if len(sentence) == 0 or not " " in sentence: print("This is not a sentence.") else: # Figure out how many upper case letters appear in a sentence for char in sentence: if char.isupper(): countCap += 1 # Report print("{0} contains {1} upper case letter(s).".format(sentence, countCap))