Question

In: Computer Science

Python 3.7.4 ## Tombstones ''' A Grave is a dictionary with two keys: * 'Name': A...

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.
"""

Solutions

Expert Solution

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!


Related Solutions

how to check if there are keys with the same values in a dictionary. python 3.0...
how to check if there are keys with the same values in a dictionary. python 3.0 for example: data = {'size': 4, 'entrance':(0, 0), 'exit':(0,0)} since the entrance and exit keys have the same value, i want the function to return None.
python Create a dictionary and insert several English words as keys and the Pig Latin (or...
python Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values. Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%. Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate...
Write code to create a Python dictionary called class. Add two entries to the dictionary: Associate the key 'class_name' with the value 'MAT123', and associate the key 'sect_num' with '211_145'
Weight Lifting Make a dictionary where the keys are the names of weight lifting exercises, and...
Weight Lifting Make a dictionary where the keys are the names of weight lifting exercises, and the values are the number of times you did that exercise.(At least 5 exercises,be creative. Nobody should have same values) Use a for loop to print out a series of statements such as "I did 10 bench presses". Modify one of the values in your dictionary, to represent doing more of that exercise. Use a for loop to print out a series of statements...
Please write in Python 3.7.4 or Higher. The Payroll Department keeps a list of employee information...
Please write in Python 3.7.4 or Higher. The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header....
**Use Python 3.7.4 *** 1. Ask the user for the number of hours worked, salary per...
**Use Python 3.7.4 *** 1. Ask the user for the number of hours worked, salary per hour and compute their salary. They will make 1.5 times salary for every hour over 40.   2. Write a program that asks the user for red, green, and blue color mixture (3 inputs); all or nothing - you can decide how to do this (0/1), (0/255), (none/all), (...). Then based on the combination display the final color: (white - 111, red - 100, green...
ising software pyton 3.5 Weight Lifting Make a dictionary where the keys are the names of...
ising software pyton 3.5 Weight Lifting Make a dictionary where the keys are the names of weight lifting exercises, and the values are the number of times you did that exercise.(At least 5 exercises,be creative. Nobody should have same values) Use a for loop to print out a series of statements such as "I did 10 bench presses". Modify one of the values in your dictionary, to represent doing more of that exercise. Use a for loop to print out...
####################################################################### ##################################### ###############python################# # RQ1 def merge(dict1, dict2): """Merges two Dictionaries. Returns a new dictionary that...
####################################################################### ##################################### ###############python################# # RQ1 def merge(dict1, dict2): """Merges two Dictionaries. Returns a new dictionary that combines both. You may assume all keys are unique. >>> new = merge({1: 'one', 3:'three', 5:'five'}, {2: 'two', 4: 'four'}) >>> new == {1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five'} True """ "*** YOUR CODE HERE ***" # RQ2 def counter(message): """ Returns a dictionary where the keys are the words in the message, and each key is mapped (has associated...
Python 3.7.4: The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible...
Python 3.7.4: The current calendar, called the Gregorian calendar, was introduced in 1582. Every year divisible by four was created to be a leap year, with the exception of the years ending in 00 (that is, those divisible by 100) and not divisible by 400. For ­instance, the years 1600 and 2000 are leap years, but 1700, 1800, and 1900 are not. Write a program that requests a year as input and states whether it is a leap year. We...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT