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

Write a python program that does the following: Store the following into a strin

ID: 3693248 • Letter: W

Question

Write a python program that does the following:

Store the following into a string variable:  The quick brown fox jumps over the lazy dog! But then the lazy dog BITES the fox and then the fox SCREAMS at the lazy dog. Now YOU tell me who is at fault?

Write the appropriate code that determines the following about the value in the string variable:

Number of upper case letters

Number of lower case letters

Number of spaces

Number of punctuation marks

Length of the string

Copy the string into a new string and replace every occurence of the word lazy with the word hyperactive.

Print all the values from step 2 above and print the original and changed strings.

Here is what I have:

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))

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)))

      print "length of string ",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))

        str1 = '%s' % s

id(s), id(str1)

(140595444686784, 140595444726400)

print str1.replace("lazy", "hyperactive")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote