Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please, need help python shell 3.4.2 instruction: Use loops to process through t

ID: 638656 • Letter: P

Question

Please, need help python shell 3.4.2

instruction: Use loops to process through the contents of a string (use decision structures and Boolean Logic, do not use repetition strures)

Standard Version

The standard version of the assignment has the following enhancements to the minimal version:

Update the code to include counts for upper-case letters, lower-case letters, word characters, and punctuation.
This will entail making multiple changes.

Variables for each count will need to be created and given an initial value.

The character checking in the loop will need to update these variables, as appropriate.

The output at the end of the script will need to label and print out these counts.

Update main so that it repeatedly asks the user for a sentence and prints out the statistics. Exit when the input is an empty string, no characters.

It makes sense to update the prompt to tell the user how to exit the program.

This should use a loop. Do not use recursion.

For the purposes of this assignment, the word characters are @ (at), # (pound/number), $ (dollar), % (percent), & (ampersand), + (plus), - (to/minus), = (equals), < (less-than), > (greater-than), * (star), / (or).

For the purposes of this assignment, the punctuation characters are ! (exclamation), ~ (tilde), ` (acute accent), ^ (carat), ( (left parenthesis), ) (right parenthesis), _ (underscore), { (left brace), } (right brace), [ (left bracket), ] (right bracket), | (vertical bar), (backslash), ; (semicolon), : (colon), " (quotation mark), ' (apostrophe), , (comma), . (period), ? (question mark).

Try to avoid redundancy as you implement (write) these new requirements.

Sample run

Enter a sentence (return to exit): WOOHOO!!! It Works!!!
Statistics on your sentence:
   Characters: 21
   Letters: 13
   Upper-case: 8
   Lower-case: 5
   Digits: 0
   Spaces: 2
   Word characters: 0
   Punctuation: 6

Enter a sentence (return to exit): 5% of 20 = 20% of 5!
Statistics on your sentence:
   Characters: 20
   Letters: 4
   Upper-case: 0
   Lower-case: 4
   Digits: 6
   Spaces: 6
   Word characters: 3
   Punctuation: 1

Enter a sentence (return to exit):
Good-bye.

Explanation / Answer

while (True):
   print ("Enter a sentence (return to exit): ");
   s = input();
   if (s == ""):
       print ("Good-Bye")
       break;
   else:
       print ("Statistics on your sentence: ")
       print ("Characters: "+str(len(s)))
       letter = 0
       u_case = 0
       l_case = 0
       num = 0
       space = 0
       word = 0
       ex = 0
       for char in s:
           if ((ord(char) >= 65 and ord(char) <= 90) or (ord(char) >= 97 and ord(char) <= 122)):
               if ((ord(char) >= 65 and ord(char) <= 90)):
                   u_case += 1;
               else:
                   l_case += 1;
               letter += 1;
           elif ((ord(char) >= 48 and ord(char) <= 57)):
               num += 1;
           elif (ord(char) == 32):
               space += 1;
           elif (char == '@' or char == '#' or char == '$' or char == '%' or char == '&' or char == '+' or char == '-' or char == '<' or char == '>' or char == '=' or char == '*' or char == '/'):
               word += 1;
           else:
               ex += 1;
       print ("Letters: "+str(letter))
       print ("Upper-case: "+str(u_case))
       print ("Lower-case: "+str(l_case))
       print ("Digits: "+str(num))
       print ("Spaces: "+str(space))
       print ("Word characters: "+str(word))
       print ("Punctuation: "+str(ex))