Home / Expert Answers / Computer Science / code-in-python-please-problem-1-is-for-reference-on-problem-2-problem-1-15-points-lo-l-pa864

(Solved): Code in python please Problem 1 is for reference on Problem 2 Problem \#1 (15 points): LO: L ...



Code in python please

Problem \#1 (15 points): LO: Learn about passing dict and list as arguments and processing them in functions.
1. Create a Pyt

bblem \#2 (15 points): LO: Learn about function reuse and processing dictionaries.
1. Add a new package named hw7p2 to the sr

Prince Harry is taller than Prince William: \( t, f \), or any to stop.t Correct!
There are 236 episodes of Friends: \( t, f

Problem 1 is for reference on Problem 2

Problem \#1 (15 points): LO: Learn about passing dict and list as arguments and processing them in functions. 1. Create a Python project named FirstName-LastName-HW7 (e.g., Jane-Doe-HW7) with the src folder. a. Add a new package named hw7p1 to the src source folder. Note that a Python package must contain an _ init_._py module. b. Add a module named anyall.py to the package hw7p1. 2. Declare a global variable (a module-level variable) Ist = [] 3. Compose a function dict_to_list() that gets a dictionary as its argument and returns a list containing four Boolean values. For example, for the argument \{'a':'f', 'b':'f', 'c':'f', 'd':'f'\}, the function dict_to_list will return a list [False, False, False, False]. 4. Compose another function is_any_true() that takes a list of four Boolean values and returns True if any of the entries in the list is True, or False otherwise. 5. Compose yet another function is_all_true() that takes a list of four Boolean values as its argument and returns True if all of the entries in the list are True, or False otherwise. a. Note that is_all_truel() and is_any_true() perform what the Python built-in functions all() and any() do; the goal of this exercise is to understand them better by creating your own versions. Therefore, do not use the built-in all() and any() functions in your solution. Note that each of the built-in functions any() and all() accepts a list of Boolean values as its argument, such as any([True, False, True, False]). b. Make sure there is no global code other than the global variable Ist in your anyall.py module. This means that you need to define a tester snippet that calls the two functions detined above to print the given output. The tester snippet looks like the one below: If __ name__=='_main_': \# call functions here. 6. Your output must look like the one below: bblem \#2 (15 points): LO: Learn about function reuse and processing dictionaries. 1. Add a new package named hw7p2 to the src folder. 2. Add a module trivia.py to the package and do the following. a. Import the module you have written for the Problem \#1 and the random module into the trivia.py. b. Define three functions with the names below in the trivia.py. Note that you need to decide on the necessary parameters and local variables. i. lists_to_dict(). This declares among others two other lists: q, a list with at least 7 trivia questions, and a, a list with matching answers, either True or False. The lists \( q \) and a then are used to create a dict qanda. When you run this function, it displays a trivia question randomly selected from the dict qanda. If user's answer is correct, the Boolean True is added to a list. If the answer is false, the Boolean False is added to the list. You may show as many trivia questions as you want. The list should look like if printed: [True, False, True, ....]. Finally, this function returns the list of Boolean values to the caller. Hints: Look into the random.choice() and list(dictionary.items()). ii. is_any_true and is_all_true functions. These two functions take the list returned from the lists_to_dict() function as their arguments. c. A tester snippet (the form is shown in the problem 1) to call the is_any_true and is_all_true from the imported module (i.e., anyall.py) with the list of Boolean values as their arguments. You also need to call the is_any_true and is_all_true functions you have defined in the importing module (i.e., trivia.py). 3. A sample run shows the output below. Your output must match the output format. Prince Harry is taller than Prince William: \( t, f \), or any to stop.t Correct! There are 236 episodes of Friends: \( t, f \), or any to stop.f Incorrect The star sign Aquarius is represented by a tiger: \( t, f \), or any to stop.t Incorrect Rabat is the capital of Morocco: \( t, f \), or any to stop.g The list of Booleans based on the user answers: [True, False, False] is_any_true() of trivia.py with [True, False, False] \( \Rightarrow \) True Built-in:any() with [True, False, False] \( \rightarrow \) True is_all_true() of trivia.py with [True, False, False] \( \Rightarrow \) False Built-in: all() with [True, False, False] ..) False is_any_true() of anyall.py with [True, False, False] \( \rightarrow \) True Built-in: any() with [True, False, False] \( \rightarrow \) True is_all_true() of anyall.py with [True, False, False] \( \cdots \) False Built-in: all() with [True, False, False] \( \rightarrow \) False


We have an Answer from Expert

View Expert Answer

Expert Answer


Firstly name the problem 1 module as anyall.py. Then the program will run SOURCE CODE; # importing problem1 anyall.py import anyall import random # li
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe