Write a function that takes in a list and a number, and returns whether or not the list contains the value n. def has_n(1st, n): """ Returns whether or not a list contains the value n. >>> has_n ( [1, 2, 2], 2) True >>> has_n ( [0, 1, 2], 3) False >>> has_n([], 5) False 1||||| "*** YOUR CODE HERE ***"
Q: Write a function that returns the greatest common divisor (GCD) of integers in a list. Use the…
A: NOTE: SINCE THE LANGUAGE OF THE CODE IS NOT MENTIONED, I HAVE USED PYTHON FOR THE SOLUTION. Define…
Q: Create a function that determines the elements in a list that can be rearranged to create a sequence…
A: Approach: Sort all the elements. Do a linear scan of the sorted array. If the difference between the…
Q: Write a function multiply_ends(nums) that takes a non-empty list of integers and returns the first…
A: 1. declare function with parameter nums i. get first element i.e. 0ith index element…
Q: The function that will a single items to the list is Oextend (...) Oadd(...) Oappend(...)…
A: The above question is solved in step 2 :-
Q: Write a function that returns a new list by eliminating the duplicate values in the list. Use the…
A: note: we are only allowed to solve one question in one post. please post-second question in a…
Q: Python Programming: 2D list The Lo Shu Magic Square is a grid with 3 rows and 3 columns that…
A: Actually, array is a collection of elements.
Q: two_sum is a Python function that takes in a list of integers (elements) and an integer number (num)…
A: Given: two_sum is a Python function that takes in a list of integers (elements) and an integer…
Q: Write a function that returns square root if each element in list. Ex: [2,4,9,144]=========> [1.4142…
A: import mathdef GetSquareRoot(nums): #list will hold square root result=[] #iterate over…
Q: Q3 - Range Function: Using the range() function Write a Python a program that generates and prints…
A: To make a list of even numbers in a given range, the lambda function and filter function are used.…
Q: PYTHON CS1 PROBLEM Define a function that takes a list of lists, glol, as a parameter. You may…
A: - We need to code the multiple of 10 in a list in python.
Q: Write the following function that tests whether a two-dimensional list has four consecutive numbers…
A: Here is the java program of the above problem. See below steps.
Q: Write a function list2DigitOdd() that creates and returns a list that contain all positive 2-digit…
A: I have given an answer in step 2.
Q: Yahtzee! Yahtzee is a dice game that uses five die. There are multiple scoring abilities with the…
A: Steps : 1. import random module 2. function to check if all 5 numbers are same in list 3. function…
Q: Exercise 2 Write a function called cumsum that takes a list of numbers and returns the cumulative…
A: Step1: we have create the function cumsum to passed the arguments Step2: we have initialize the list…
Q: The two-dimensional lists m1 and m2 are strictly identical if their corresponding elements are…
A: Program Approach: Create a boolean function which takes two matrices.Using for loop check whether…
Q: Program - Python Write a function min_max() that takes a list s as an argument, and print the…
A: In this question, it is asked to create a python program for the given problem statement. The…
Q: Write a function that accepts two lists as it's only arguments. The function should return a new…
A: PYTHON code for above : # required function for above def func(list1, list2): list3 = list1…
Q: PYTHON CODE Write a function list3Digit10() that creates and returns a list that contain all…
A: Refer to step 2 for the answer.
Q: Write the following function that tests whether the list has four consecutive numbers with the same…
A: #declarer functiondef isConsecutiveFour(values): #return the values return sorted(values) ==…
Q: Write a function that will accept a list of integers and return the sum of the contents of the…
A:
Q: Write a function called remove_odd that takes a list of numbers that have both even and odd numbers…
A: Given: Write a function called remove_odd that takes a list of numbers that have both even and odd…
Q: Write a function that accepts two arguments, a list and a number n. The list contains numbers. The…
A: here in this question we have asked to write a program which take a list and an integer input from…
Q: a- Write a Python function Salary_levels, that takes a list as an argument and returns the number of…
A: You can return many values from function as tuple and this is the beauty of Python
Q: Write the following function that returns the location of the largest element in a two-dimensional…
A: According to the Question below the Solution: Output:
Q: Our second pattern is the mapped list pattern, described in video 4 3 mapped list pattern. Often we…
A: The for loop in Python is used to iterate the statements or a part of the program several times. The…
Q: The function should be written in python language. Write a function called "zero_triples" to return…
A: Call a function find_triples() to fill triplesInside function find_triples()Take three numbers in…
Q: 8-9. Messages: Make a list containing a series of short text messages. Pass the list to a function…
A: # 8-9. Messages: Make a list containing a series of short text messages. Pass the list # to a…
Q: Create a list L containing at least 10 values ranging from j to k. Using a for loop, code a function…
A: Since no programming language is mentioned, I am using python. Algorithm: Start Initialize list L…
Q: Complete the reverse_list() function that returns a new string list containing all contents in the…
A: The python program is given below:
Q: Write a function named listReplace that takes 3 arguments: list1, tuple1, and tuple2. The function…
A: PROGRAM EXPLANATION: Define a function list Replace. This function will receive 3 arguments: list1,…
Q: In Python Use the Design Recipe to write a function has_duplicates, which consumes a list and…
A: This program returns true when a list has duplicate value, if the list has not any duplicate value…
Q: program7.py This assignment requires the main function and a custom value-returning function. The…
A: Below is the complete solution with explanation in detail for the given question in Python…
Q: Analyze the given function below that takes a binary list of size (n) and returns the number of 1's,…
A: Given program contains three variables zeroCount, oneCount, onesSum. All these variables are…
Step by step
Solved in 3 steps with 1 images
- Write a function that returns the greatest common divisor (GCD) of integers in a list. Use the following function header:def gcd(numbers):Write a test program that prompts the user to enter five numbers, invokes the function to find the GCD of these numbers, and displays the GCD.Exercise, maxCylinderVolume F# system function such as min or methods in the list module such as List.map are not allowed Write a function maxCylinderVolume that takes a list of floating-point tuples that represent dimensions of a cylinder and returns the volume of the cylinder that has the largest volume. Each tuple has two floating point values that are both greater than zero. The first value is the radius r and the second value is the height h. The volume of the cylinder is computed using ??2h. The value π is represented in F# with System.Math.PI. If the list is empty, return 0.0. Examples: > maxCylinderVolume [(2.1, 3.4); (4.7, 2.8); (0.9, 6.1); (3.2, 5.4)];;val it : float = 194.3137888> maxCylinderVolume [(0.33, 0.66)];;val it : float = 0.2257988304python program plz
- a- Write a Python function Salary_levels, that takes a list as an argument and returns the number of the high salaries (salary>=5000), the average salaries(1000<=salary<5000, and the low salaries (salary<1000). You can use the following list : salaries= [500,1070,1450,6500,9000,940,450,400,600,2750,1100,8400,1500,900,1200] b- Use the above function to print the counts of the high, average, and low salaries. N.B: the codes of parts a and b should be included in your answer.Q1:Write a function that returns a new list by eliminating theduplicate values in the list. Use the following function header:def eliminateDuplicates(lst):Write a test program that reads in a list of integers, invokes the function,and displays the result. Here is the sample run of the program Enter ten numbers: 2 3 2 1 6 3 4 5 2The distinct numbers are: 1 2 3 6 4 5 Q2:Write a program that reads in your Q1 Pythonsource code file and counts the occurrence of each keyword in the file.Your program should prompt the user to enter the Python source code filename. This is the Q1: code: def eliminateDuplictes(lst):newlist = [] search = set() for i in lst: if i not in search: newlist.append(i) search.add(i) return newlist a=[] n= int(input("Enter the Size of the list:")) for x in range(n):item=input("\nEnter element " + str(x+1) + ":") a.append(item) result = eliminateDuplictes(a) print('\nThe distinct numbers are: ',"%s" % (' '.join(result)))Python Language Writing an alternating sum function.
- solution in python languageWrite a function summax2 : int list -> int = that takes an int list and returns the sum of the 2 largest integers in it. 1 # summax2 [1;4;6;2;7;8; 3 ; 10 ; 4; - 1] ; ; 2 - : int = 18 3 # summax2 [1;4];; 4 - : int = 5 5 # summax2 [1]; ; 6 - : int - 1 7 # summax2 []; ; int = 0two_sum is a Python function that takes in a list of integers (elements) and an integer number (num) and returns True if there exist two values in elements that add up to num, otherwise, function returns False. def two_sum(elements: List[int], num: int): for i in range(len(elements)): for j in range(i + 1): if elements[i] + elements[j] == num: return True return False Study above function and answer below questions: A. What is time complexity of two_sum? B. Is it possible to improve on above algorithm performance (in terms of its asymptotic cost)? If yes, describe your algorithm, be detailed as much as possible.
- Yahtzee! Yahtzee is a dice game that uses five die. There are multiple scoring abilities with the highest being a Yahtzee where all five die are the same. You will simulate rolling five die 777 times while looking for a yahtzee. Program Specifications : Create a list that holds the values of your five die. Populate the list with five random numbers between 1 & 6, the values on a die. Create a function to see if all five values in the list are the same and IF they are, print the phrase "You rolled ##### and its a Yahtzee!" (note: ##### will be replaced with the values in the list) Create a loop that completes the process 777 times, simulating you rolling the 5 die 777 times, checking for Yahtzee, and printing the statement above when a Yahtzee is rolled. When you complete the project please upload your .py file to the Project 2 folder by the due date.Problem AttachedPYTHON CS1 PROBLEM Define a function that takes a list of lists, glol, as a parameter. You may assume that the inner lists in glol are lists of positive integers. Your function should return True if at least one of the inner lists in glol contains two or more multiples of 10. Otherwise it should return False. For example: If glol = [ ] then your function returns False. If glol = [[ ], [4, 2]] then your function returns False. If glol = [[10, 2, 6, 8], [12, 6], [15, 20, 5]] then your function returns False. If glol = [[10, 2, 6], [12, 6], [10, 2, 70, 15], [15, 10, 5]] then your function returns True as the inner list [10, 2, 70, 15] contains 10 and 70. If glol = [[10, 2, 6], [12, 6], [10, 7, 15], [50, 10, 50, 4, 6]] then your function returns True as the inner list [50, 10, 50, 4, 6] contains 50 twice. 6. If glol = [[10, 20, 6, 90], [12, 6], [ 7, 3, 15], [50, 10, 50, 4, 7]] then your function returns True as the inner lists [50, 10, 50, 4, 7] and [10, 20, 6, 90] contain more…