Question

Python 3 Monster = {"name": str, "kind": str, "spookiness": int, "undead?": bool} ''' M5. Define a...

Python 3

Monster = {"name": str, "kind": str, "spookiness": int, "undead?": bool}

'''
M5. Define a function `count_spooky_monsters` that consumes a list of monsters
and produces an integer indicating how many monsters have a spookiness of
2 or more.
'''

'''
M6. Define the function `count_vampires` that consumes a list of monsters
and produces an integer indicating how many monsters are of the kind
"vampire".
'''

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find explanation of code in comments.

#START of code

def cout_spooky_monsters(monsters_list):

    # initialize spookiness variable

    spookiness_count = 0

    # iterate over monsters_list.

    for monster  in monsters_list:

        if monster["spookiness"] >= 2:

            spookiness_count += 1

    return spookiness_count

def count_vampires(monsters_list):

    # initialize vampire_count function

    vampires_count = 0

    # iterate over monsters_list

    for monster  in monsters_list:

        if monster["kind"] == "vampire":

            vampires_count +=1

    return vampires_count

if __name__ == "__main__":

    monsters_list=[{"name": "Monster name", "kind": "vampire", "spookiness": 2, "undead?": True},

                    {"name": "Monster name", "kind": "vampire", "spookiness": 3, "undead?": True},

                    {"name": "Monster name", "kind": "zoombie", "spookiness": 0, "undead?": True},

                    {"name": "Monster name", "kind": "zoombie", "spookiness": 6, "undead?": True}

                ]

    print("Number of monsters that have a spookiness of two or more is",cout_spooky_monsters(monsters_list))

    print("Number of monsters are of the kind vampire is",count_vampires(monsters_list))

# END of code

Add a comment
Know the answer?
Add Answer to:
Python 3 Monster = {"name": str, "kind": str, "spookiness": int, "undead?": bool} ''' M5. Define a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition:...

    def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition: price_list is a list of lists in the following format: [ [str, int], [str, int], ... ] where each 2-element list represents a name (str) and a price (int) of an item. price_list has at least one element. >>> price_list = [["apple", 1], ["sugar", 5], ["mango", 3], ... ["coffee", 9], ["trail mix", 6]] >>> most_expensive_item(price_list) """ please complete the function body in Python

  • Python problem. 3. (6 pts) Define the following four sorting functions: each takes an argument that...

    Python problem. 3. (6 pts) Define the following four sorting functions: each takes an argument that is a list of int or str or both values (otherwise raise an AssertionError exception with an appropriate error message) that will be sorted in a different way. Your function bodies must contain exactly one assert statement followed by one return statement. In parts a-c, create no other extra/temporary lists other than the ones returned by calling sorted. a. (2 pts) Define the mixed...

  • Language: Python Topic: API and JSON Function name: min_pop_countries Parameters: region (str), num (int) Return: list...

    Language: Python Topic: API and JSON Function name: min_pop_countries Parameters: region (str), num (int) Return: list of tuples Description: You are working on a project for your Demography class and you are tasked with finding the top num most populous countries in a given region . Instead of looking up on the Internet, you decide to apply your CS1301 knowledge of APIs and write a function to solve the problem for you. Develop a function that takes in a region...

  • Python String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description:...

    Python String Product Function Name: string Multiply Parameters: sentence (str), num (int) Returns: product (int) Description: You're texting your friend when you notice that they replace many letters with numbers. Out of curiosity, you want to find the product of the numbers. Write a function that takes in a string sentence and an int num, and find the product of only the first num numbers in the sentence. If num is 0, return 0. If num > O but there...

  • In Ocaml Define the function everyNth : ('a list) -> int -> ('a list) that will...

    In Ocaml Define the function everyNth : ('a list) -> int -> ('a list) that will take a list and a positive number i and produce a new list that has every element whose position in the given list is a multiple of i. Some example outputs for the function follow: # everyNth [1;2;3;4] 2;; - : int list = [2; 4] # everyNth [1;2;3;4] 1;; - : int list = [1; 2; 3; 4] # everyNth [1;2;3;4;5;6] 3;; -...

  • IN PYTHON 3 LANGUAGE, please help with function, USE RECURSION ONLY def im(l: 'an int, str,list,tuple,set,or...

    IN PYTHON 3 LANGUAGE, please help with function, USE RECURSION ONLY def im(l: 'an int, str,list,tuple,set,or dict') -> 'an int, str, tuple, or frozenset'      pass    SAMPLE OUTPUT: The following call (with many mutable data structures) imm(1)   returns 1 imm('a') returns 'a' imm( (1, 2, 3))   returns (1, 2, 3) imm( frozenset([1, 2, 3]))   returns frozenset({1, 2, 3}) imm( [1, 2, 3, 4, 5, 6])   returns (1, 2, 3, 4, 5, 6) imm( [1, 2, [3, [4], 5], 6])  ...

  • I need help with this problem. Using Python please. Thanks Construct a class “Monster” with the...

    I need help with this problem. Using Python please. Thanks Construct a class “Monster” with the following attributes: self.name (a string) self.type (a string, default is ‘Normal’) self.current_hp (int, starts out equal to max_hp) self.max_hp (int, is given as input when the class instance is created, default is 20) self.exp (int, starts at 0, is increased by fighting) self.attacks (a dict of all known attacks) self.possible_attacks (a dictionary of all possible attacks The dictionary of possible_attacks will map the name...

  • Python Question: Define the function high_score that consumes a list of integers (representing scores in a...

    Python Question: Define the function high_score that consumes a list of integers (representing scores in a game) and produces an integer representing the highest score in the list. Ignore scores less than 100, and stop processing values if you encounter -999. If the list is empty, return the value None instead. It is up to you to decompose this function (or not) however you want. Here is my code so far: from cisc108 import assert_equal def high_score(scores: [int])->int: max_num =...

  • HELP....ITS CLOSING TONIGHT INFSCI 0017 – Assignment 4 You are doing an internship in a company...

    HELP....ITS CLOSING TONIGHT INFSCI 0017 – Assignment 4 You are doing an internship in a company specialized in create role-­‐playing computer games. As a part of the programming team, you are asked to implement and test the first version of a RolePlayer class. In the game, a RolePlayer is a knight with the mission of fight and kill monsters: vampires and werewolves. As the player defeat monsters, he/she gains points. The player is considered trainee if he/she has less than...

  • Summary task: C++ language; practice combining tools(functions, arrays, different kind of loops) to solve somewhat complex...

    Summary task: C++ language; practice combining tools(functions, arrays, different kind of loops) to solve somewhat complex problem. Description A Valiant Hero is about to go on a quest to defeat a Vile Monster. However, the Hero is also quite clever and wants to be prepared for the battle ahead. For this question, you will write a program that will simulate the results of the upcoming battle so as to help the hero make the proper preparations. Part 1 First, you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT