In: Computer Science
Python 3.7.4
## Tombstones
'''
A Grave is a dictionary with two keys:
* 'Name': A string value with the grave's occupant's name
* 'Message': A string value with the grave's message
'''
Grave = {'name': str, 'Message': str}
'''
G1. Define the function `count_grave_all` that consumes a list of
graves
and produces an integer representing the number of characters
needed to
write all of the message of the grave. Include spaces and new
lines.
'''
'''
G2. Define the function `count_grave_characters` that consumes a
list of graves
and produces an integer representing the number of characters
needed to
write all of the message of the grave. Do not count spaces and new
lines.
'''
'''
G3. Define a function named `estimate_grave_cost` that consumes a
list of graves
and produces an integer representing the total estimate lettering
cost by
multiplying the number of letters on the grave (ignoring spaces and
newlines) by
the cost of writing a letter ($2).
'''
"""
G4. Define a function named `count_shouters` that consumes a list
of graves
and produces an integer representing the number of graves that had
their
messages in all capital letters. Hint: use the `.upper()`
method.
"""
Here is the code you need:

def count_grave_all(list_of_graves):
total_chars=0
for each_grave in list_of_graves:
total_chars = total_chars + len(each_grave['Message'])
return total_chars
def count_grave_characters(list_of_graves):
total_chars=0
for each_grave in list_of_graves:
total_chars = total_chars + len(each_grave['Message'])-
each_grave['Message'].count(' ') -
each_grave['Message'].count('\n')
return total_chars
def estimate_grave_cost(list_of_graves):
total_chars=0
for each_grave in list_of_graves:
total_chars = total_chars + len(each_grave['Message'])-
each_grave['Message'].count(' ') -
each_grave['Message'].count('\n')
return total_chars*2
def count_shouters(list_of_graves):
count=0
for each_grave in list_of_graves:
if(each_grave['Message']== each_grave['Message'].upper()):
count = count + 1
return count
list_of_graves=[{'name':'first','Message':'this is a sample message\n'}, {'name':'second','Message':'this is another sample message\n'}]
print(count_grave_all(list_of_graves))
print(count_grave_characters(list_of_graves))
print(estimate_grave_cost(list_of_graves))
print(count_shouters(list_of_graves))
Output:

Hope you like it!
Please provide comments if you have any doubts!