Need done in python, picture of the homework question is provided.
Answer any ONE (highlight your choice) of the following two problems:
Problem A
Write a function definition which has two parameters, both lists. The function is supposed to return the “product” of the two parameters. The result which is returned is a new list whose elements are the products of corresponding elements from each list. If the lists are not the same size, return an empty list. Assume the elements are numeric. Use ONE return statement. This function does no input or output.
Example: times_list( [2, 4, 5], [3, 4, 9]) returns [6, 16, 45].
Example: times_list( [3, 15], [1, 2, 3]) returns [ ]
Problem B
Write a program that plays a number-guessing game with the user. The program first generates a random number in the range 1 through 50, inclusive. The user then enters a guess. If the user matches the random number, the game is over, and shows how many guesses it took. If the number the user entered is less than the random number, the program says “Too low”. Otherwise, if the user input is greater than the random number, the program says “Too high”. The program keeps a count of how many guesses the user takes to correctly guess the number and reports it at the end of the game.
Sample run:
What's your guess? 30
Too high
What's your guess? 15
Too low
What's your guess? 22
Too high
What's your guess? 18
Too high
What's your guess? 17
Game Over
It took you 5 guesses.
ANS:
Step by stepSolved in 2 steps
- Need help. Its in C++. Whats the main idea herearrow_forwardPython code please help, indentation would be greatly appreciatedarrow_forwardPython Practice Functions 1. Write a function that takes in a list and returns a new list that has the elements of the parameter in reverse order 2. Write a function to return the index of the maximum element in a list 3. Write a function that takes in a list returns a new list with only the odd elements from the parameter list. 4. Write a function that takes in two lists. Each parameter represents a point, e.g., [1,1]. Return the Euclidean distance between the two points. 5. Write a function that takes in a filename. Open the file, and return a list where each element is a line from the file. 6. Write a function that takes in a filename and a list. Write the contents of the list to the file. Each element should be on its own line in the file. Classes 1. Create a class titled BankAccount. 2. Create a constructor that takes an ID parameter and initial deposit amount parameter. The constructor should set an 'id' member to the ID parameter and set the 'balance' member to the initial…arrow_forward
- Write a function that accepts two lists as it's only arguments. The function should return a new list containing all the elements of the two list arguments. For example, if the function was passed the lists [1, 2, 3] and [4, 5, 6], it would return a new list containing [1, 2, 3, 4, 5, 6]arrow_forwardcan you write in C++arrow_forwardThe "outer" list data structure of 2-dimensional lists can be matrix-like ( having same number of elements in each "inner" list or "row"), or it can be ragged (having different number of elements in each "row"). a) Write a Python function called raggs that takes a single argument that is a reference to a 2-d list, and returns the value True if the 2-d list is ragged, and False otherwise. b) Demonstrate that the function works for all relevant cases by inputting different example values.arrow_forward
- 7. Given two lists A and B, write a function to compute the difference A – B, where A – B is the list of elements that are in A but not in B. For example, if A is '(6 7 8 9) and B is (7 9) then A – B is '(6 8).arrow_forwardpython: def character_gryffindor(character_list):"""Question 1You are given a list of characters in Harry Potter.Imagine you are Minerva McGonagall, and you need to pick the students from yourown house, which is Gryffindor, from the list.To do so ...- THIS MUST BE DONE IN ONE LINE- First, remove the duplicate names in the list provided- Then, remove the students that are not in Gryffindor- Finally, sort the list of students by their first name- Don't forget to return the resulting list of names!Args:character_list (list)Returns:list>>> character_gryffindor(["Scorpius Malfoy, Slytherin", "Harry Potter,Gryffindor", "Cedric Diggory, Hufflepuff", "Ronald Weasley, Gryffindor", "LunaLovegood, Ravenclaw"])['Harry Potter, Gryffindor', 'Ronald Weasley, Gryffindor']>>> character_gryffindor(["Hermione Granger, Gryffindor", "Hermione Granger,Gryffindor", "Cedric Diggory, Hufflepuff", "Sirius Black, Gryffindor", "JamesPotter, Gryffindor"])['Hermione Granger, Gryffindor', 'James…arrow_forward1) Write a function that takes one argument, a list named sample-list. 2 ) If the length of the sample-list is > 8, then use the last element of sample-list and return it in a list. 3) If the length of sample-list is <= 8 and > 4, then return the first elements of sample-list in a list. 4) Otherwise, return the string “This is the third option.”. Please make sure to test your function!!! and explain your code shortly by adding comments to each line.arrow_forward
- Write a function count_evens(nums) that takes a list of ints called nums and returns the number of even ints in the given list. Note: the % "mod" operator computes the remainder, e.g. 5 % 2 is 1.arrow_forward18) Write a function that takes in 2 lists and checks whether they have the same elements in the same order. If the elements are all the same, the function should return the string “same”. If any of the elements are different, the function should return the string “different”. The definition of the function should be: Def equals(a, b):arrow_forwardWrite pseudocode for a Python program that 1) defines a list to store the choice of +, -, *, and /, defines functions to support the calculations, and calls them in response to user inputs. Test each of the four calculations, and turn in the pseudocode, the Python program, and a screenshot of your output displaying the four tests in the Python shell.Run your program and test all four calculations,Take a screenshot of your program’s output from the Python shell.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education