Problem 5-Write a function that get a list of numbers as input and checks to see if it is a set or not. In a set, there are no repetitions of items. (Note: You should do this without using the built-in set function) IsSet ([5,8,0,4,2]) True >>> IsSet([3,6,8,4,5,2,6,2]) False
Q: Write a python program to get input choice from the user and perform the operations given Choice…
A: Program: #input choice choice=int(input("Input choice: ")) #if Choice is 1 if choice==1: #input 1…
Q: or the following block of code, select the most appropriate Big-O running time in terms of the input…
A: Here in this question we have given a code segment and we have asked to find the time complexity in…
Q: You are given two variables one is associated with a float ahd hame talweight, containing the weight…
A: Please find the answer below :
Q: We use array method _ to produce two-dimensional arrays from one-dimensional ranges. a. shape b.…
A: I have given an answer in step 2.
Q: draw a scatter plot using random distributions to generate balls of different sizes
A: Python Code and output given below:
Q: The script has four steps: 1. Read a list of integers (no duplicates). 2. Output the numbers in the…
A: Solution: Python program: # Declare global variable count_swap and comparisons count_swap = 0…
Q: Write a program to print the following pattern 123456 12345 1234 123 12
A: Following is the python program that: declares a variable number to take a count on numbers to be…
Q: Salary Options: You are offered two salary options for a fixed number of days. Option 1: $100 per…
A: def option1(n): salaryFromOption1=100*n; #option1 is paying 100 everyday return…
Q: Prompt the user to enter a value for yards, which must be greater than 0 and not greater than 10 For…
A: Solution :
Q: Which of the following is always true about conditions? O Conditions always ask a yes or no question…
A: True about condition in above given option
Q: Which widget allows to create screen inside another screen?
A: The answer to this question is Frame
Q: 1. Given the initial statements s1 = [2,1,4,3] s2 = ['c','a','b'] show the result of evaluating each…
A: I give the output along with an explanation
Q: Write a program that ask the user to input a single character and print a message "It is a vowel",…
A: While doing programming in any programming language, you need to use various variables to store…
Q: 2. Factors a) Define a function named printFactors() with a parameter n. This function prints all…
A: #adef printFactors(n): #takes parameter n #printing all factors of n in a line for i in…
Q: Write a class called Quadratic, which implements a quadratic polynomial with integer coefficients.…
A: Below is the required code in python and sample output:
Q: Assume the variable authors references a list. Write a for loop that displays each author in the…
A: authors = ["Chetan Bhagat", "Amrita Pritam", "Jhumpa Lahiri", "Khushwant Singh", "R. K. Narayan"]…
Q: An ! character as alternative separator for the print function? sep is ! separate = ! %3D sep >> '!'…
A: EXPLANATION: The sep operator is used to perform formatting in the string and information in the…
Q: Modify the cone class you have already written in the lab as follows: - Modify the constructor so…
A: Algorithm for the code:- 1. Start 2. Define a class named 'Cone' with three instance variables…
Q: The purpose of this question is to write a program that will perform these nutritional calculations.…
A: We have to write the code in python. We have no. of grams of fat and number of grams of…
Q: What is the correct combination of function and parameter to create a pie chart in Matplotlib?
A: It is a python library which can be used to create various visualizations such as charts, graphs and…
Q: 5- Write a separate function for each of the following questions. Place all the functions in func.py…
A: Python program to solve the given problem is below. ***Note: According to Bartleby policy we…
Q: Define a function named translate english_french(french_dictionary, word) which takes a translation…
A: First we have to Install Proper Python Modules > Go To Your Terminal Type : - pip Install…
Q: Why is it useful to store information with different data types? When do you choose to use a list…
A: A list a mutable collection of elements. It allows for storing mixing element types that can be…
Q: Which of the following is an invalid statement? O abc = 10,000,000 O ab_c = 1,000,000 O a,b,c =…
A: The Answer is in step2
Q: Write a program that ask the user to enter his/her letter grade and then respond with an appropriate…
A: grade = input("Enter your grade : ") #taking user inputif(grade == 'a' or grade == 'A'):…
Q: Copy the above code into your Python file, and then write a class Mansion that inherits from House.…
A:
Q: Write a python class called fraction that represents a fraction with a numerator and a denominator.…
A: Functions: __init__() is used to initialise the value of numerator and denominator gcd() is used to…
Q: Write a program that requests the floating number of hours a person works in a given week and the…
A: wagePerHour=float(input("Enter hourly wage: ")); #input wage per…
Python
Step by step
Solved in 4 steps with 2 images
- def cartesianproduct(lst): """Takes a list of sets/frozensets and computes their Cartesian product""" cartesianproduct: This function should accept a list of one or more sets or frozensets (you can convert between them using set(fro_st) and frozenset(st)). Its output is a set or frozenset encoding the cartesian product; thus a list of two sets [{0,1}, {1,2}] could give back {(0,1),(0,2),(1,1),(1,2)}. In general, an input list of length N will yield a set of tuples of length N each.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.Recamán's sequence def recaman(n): Compute and return the first n terms of the Recamán's sequence, starting from the term a1 = 1.Note how the definition for the current next element depends on whether a particular number is already part of the previously generated part of the sequence. To let your function execute in a speedy fashion even when generating a sequence that contains millions of elements, you should use a set to keep track of which values are already part of the previously generated sequence. This way you can generate each element in constant time, instead of having to iterate through the entire previously generated list. The better technique that saves time by using more memory can create this list arbitrarily far in linear time, and should therefore be fast even for millions of elements, at least until it runs out of memory. n Expected result 10 [1, 3, 6, 2, 7, 13, 20, 12, 21, 11] 1000000 (a list of million elements whose last five elements are [2057162,1057165,…
- Question > Not complete Marked out of 1.50 Flag question Previous page Write a recursive function named get_palindromes (words) that takes a list of words as a parameter. The function should return a list of all the palindromes in the list. The function returns an empty list if there are no palindromes in the list or if the list is empty. For example, if the list is ["racecar", "hello", "noon", "goodbye"], the function should return ["racecar", "noon"]. A palindrome is a word that is spelled the same forwards and backwards. Note: The get_palindromes() function has to be recursive; you are not allowed to use loops to solve this problem. For example: Test words = ["racecar", "hello", "noon", "goodbye", "test", 'aibohphobia'] ['racecar', 'noon', 'aibohphobia'] print (get_palindromes (words)) print (get_palindromes ([])) print (get_palindromes (['this', 'is', 'test'])) Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) Result Precheck Check [] [] Next pagePart 3 – Longest Common Sequence This part requires that you implement a C function that takes in as parameters two arrays and their sizes. This function is required to find the longest common sequence of numbers in these arrays. The prototype of the function MUST be: void longestMutualSequence (int firstArr[), int secondArr[], int sizeA, int sizeB); For example, if you have int a[] = {1, 2, 3, 4, 1000, 90, 100, 110, 200, 202}; and int b[] = {1, 1, 2, 3, 90, 100, 110, 200, 202, 600};, your function should output. Longest Common Sequence is 90, 100, 110, 200, 202. If there are two common sequences of the same size, your function should print out the first common sequence found.Mark the these with true or false and correct the false And thank you :)
- 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)))onsider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user, ends with ‘#’. It should be stored in a table (or array), called TAMUK. The number of each of these letters is unknown. We have a function, called SWAP(TAM,i,j), which places the ith letter in the jth entry of string TAM and the jth letter in the ith entry of TAM. Note that SWAP(TAM,i,j) is defined for all integers i and j between 0 and length(TAM)–1, where length(TAM) is the number of letters of TAM. 1. Using our algorithmic language, write an algorithm, called Sort_TAM, which sorts the letters in the array TAMUK in a way that all T’s appear first, followed by all A’s, and followed by all M’s. The algorithm Sort_TAM should have one parameter: The array TAMUK. Also, your solution is correct only if the following four constraints are satisfied: - Constraint 1: Each letter (‘A’, ‘M’, or ‘T’) is evaluated only once. - Constraint 2: The function SWAP(TAM,i,j) is used only when it is…Part 2: Unroll Write a function called unroll, which takes in a square array of arrays (i.e. a grid with n rows and n columns). An input could look like this: const square = [ [1, 2, 3, 4], [5, 6, 7, 8], ]; [9, 10, 11, 12], [13, 14, 15, 16] unroll should take in such a square array and return a single array containing the values in the square. You should obtain the values by traversing the square in a spiral: from the top- left corner, move all the way to the right, then all the way down, then all the way to the left, then all the way up, and repeat. For the above example, unroll should return [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10].
- II II II Write a function named `vectorSum(11, 12) that takes two lists of numbers and adds the numbers in 12 on 11, one by one. If 12 is shorter than 11, then 12 recycles from the beginning once it is over. If 12 is longer than 11, then only the first part of 12 that matches the length of 11 is considered. Your function must return the summed up resulting list. For example, vectorSum([1,2,3,4,5], [1,2,3]) returns [2,4,6,5,7] because: 1,2,3,4,5 + + + + + 1,2,3,1,2 -> Here, 12 recycles from the beginning = = = = = 2,4,6,5,7 vectorSum([1,2,3], [1,2,3,4,5]) returns [2,4,6] because: 1,2,3 + + + 1,2,3,4,5 -> Here, only the first 3 items of 12 are used = = = 2,4,6 vectorSum([1,2,3,4,5], [1,2,1,2,1]) returns [2,4,4,6,6] because: 1,2,3,4,5 + + + + + 1,2,1,2,1 -> Here, length of 12 matches the length of 11 = 2,4,4,6,6 You can assume that 11 and 12 are not empty. def vectorSum (11, 12): # remove the following line to solve this question returnProbelm part 1: Define a function called common_divisors that takes two positive integers m and n as its arguments and returns the list of all common divisors (including 1) of the two integers, unless 1 is the only common divisor. If 1 is the only common divisor, the function should print a statement indicating the two numbers are relatively prime. Otherwise, the function prints the number of common divisors and the list of common divisors. Complete each to do with comments to expalin your process. Problem part 2: complete the following todo's and make comments to explain each step # TODO: Define the function 'common_divisors' with two arguments 'm' and 'n'. # TODO: Start with an empty list and append common divisors to the list. # TODO: Create a conditional statement to print the appropriate statement as indicated above. Problem part 3: Call the function common_divisors by passing 5 and 38. Your output should look like this: 5 and 38 are relatively prime. # TODO: Call…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.2257988304