1) 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.
Q: Write a function that takes list and a number (x) as parameters. Assume list contains only numbers,…
A: - We need to solve the number list problem in python.
Q: Write and test a function shuffle (my List ) that scrambles a list into arandom order, like…
A: Given: Write and test a function shuffle (my List ) that scrambles a list into arandom order, like…
Q: print_smallest_and_largest_even Write a function named (numbers_list) that takes a list of numbers…
A: Finding smallest and largest Even number from list using python
Q: 3. Write a function that takes in a list returns a new list with only the odd elements from the…
A: Note: we are only allowed to solve one question in one post.Since 1 and 2 are done I am solving the…
Q: Prompt the user to enter a string of their choosing (assume no punctuation). Store the text in a…
A: Since the Programming language is not mentioned in the question, we will answer this question in…
Q: Write a function that accepts a list as an argument and calculates the sum of each element of the…
A: Program: Programs are used to interact with computer systems and solve complex problems. The main…
Q: Write a function create_list_MtoN that will create and return a list of integers from m to n (where…
A: def create_list_Mton(m,n): lis=[] if(m>n): # for m is greater than n for…
Q: C function takes a simply-linked list as an input argument. It modifies the list by moving the last…
A: Lets see the solution.
Q: Part 1 Add this comment:# LAB 7: Part 1 Write a Python function list_Freq that takes the following…
A: Initialize a variable count=0 , variable 'answer= list[0] 'and then traverse the list using 'for'…
Q: Exercise 3: Single parameter Write a function print_even() which • takes a list of integer numbers…
A: A number is said to be an even number if the number is divisible by 2 and the remainder of the…
Q: numPairs Write a function numPairs that accepts two arguments, a target number and a list of…
A: Actually, python is a easiest programming language. It has a concise(less) code.
Q: Write a function named mostCharacters that takes a list of strings as an argument and a character as…
A: we want a function that names"mostCharacters'" that take a list of strings as an argument and a…
Q: Python Programming - (Duplicate Elimination)
A: Python Programming Part 1: Python program to display sorted list of numbers and strings containing…
Q: Write a function for the user to enter a positive integer n with a value between 10 and 1000. If…
A: Q: As per bartleby policy, we can only answer one part per question. Please post other parts in a…
Q: Write a function lastDigits() that takes a list of numbers as parameter, returns a string made of…
A: Required: Write a function lastDigits() that takes a list of numbers as parameter, returns a string…
Q: Write a function toSentence : string list -> string = that takes a string list and concatenates its…
A: Since no programming language is mentioned, I am using python. Code: def toSentence(stringList):…
Q: Write a function called CommonElements that takes in two ADT Lists and returns a new ADT List with…
A: The language of function is C++ as no language is mentioned but logic remains the same Function to…
Q: complete the following function. // It is the same as observeCounter except that f has a parameter…
A: // It is the same as observeCounterList except that f has a parameter of type Array[Counter] not…
Q: Focus on: Basic list operations, methods, use of functions, and good programming style Part 1.…
A: As per our guidelines we are supposed to answer only one question. Kindly repost the remaining…
Q: What is the best way to reuse lines of code? A. Copy and paste them wherever needed B. Lines of code…
A: The above question is solved in step 2 :-
Q: Create a function that takes a string of strings and replaces the same members with only numbered…
A: I give the code in Python along with output and code screenshot
Q: How can I ensure the Capital letters are in the right place?"** Explanation 1) Below is program…
A: Here we have the code that reverses the occurrence of the vowel in the string. In the code, we have…
Q: Write a function lastDigits() that takes a list of numbers as parameter, returns a string made of…
A: The remainder of a number can be found using % operator and this is converted to string and appended…
Q: primeFac (Perkovic, Problem 5.42) Write a function primeFac that computes the prime factorization of…
A: PROGRAM INTRODUCTION: Start the definition of the function to find the prime factors of the number…
Q: 20-Write a function listFirstChars() that takes a list of strings as parameter, returns a new list…
A: I have given an answer in step 2.
Q: 15- Write a function that takes two positive integers as a parameter .The first integer is the…
A: Provided below is the program which takes two positive integers from user for number of heads and…
Q: Python Practice Functions 1. Write a function that takes in a list and returns a new list that has…
A: Slicing technique is used to make a copy of the list in reverse order def revFunc(x): newList =…
Q: Notice that all of the data in the inner lists are represented as strings. You are to write the…
A: Step 1: Define is_number() function which checks whether the passed value is a number and returns…
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: 2. Write a function which will take list as a argument and this function will return a reversed list…
A: Given :- Write a function which will take list as a argument and this function will return a…
Q: Practice Project For practice, write a program that does the following. Table Printer Write a…
A: #printTable function def printTable(tableData): colWidths=[0]*len(tableData) for i in…
Q: IN JS ONLY Create a function that takes a list and string. The function should remove the letters in…
A: Coded usign JavaScript.
Q: Write a function called chop_list that takes a list, modifies it by removing the first and last…
A: def chop_list(list1): # remove first element list1.pop(0) # remove last element list1.pop() # return…
Q: Let L is a list object of integers, write a function that prints the two items in L such that they…
A: Program Approach: Include header files. Define function closet that will find the closet pair of…
Q: Write a function that concatenates all the strings in a list. The concatenation of all the strings…
A: let join separator = function | [] -> "" | [str] -> str | str::strs -> let buf =…
Q: Write a program in F#, listOfPrime, to construct a list of all prime numbers within a given range of…
A: Doing this code using Sieve of Erathosthenes, The Sieve of Erathosthenes is an old procedure for…
Q: 3) Write a function called sample that must work similar to random.sample in random package Syntax :…
A: Given:
Q: Create a function that takes a list of numbers and returns a list where each number is the sum of…
A: Sample Response: #python3 program#function to takes a list of numbers and returns a list where each…
Q: True or false? When a list is passed to a function, a new list is created and passed to the…
A: List List is used to store the multiple items in the single variable. Items in list are changeable,…
Q: const std::vector more_words { "this is a sentence.", "this is also words "another line in one",…
A: Standard Template Library(STL): Algorithms The header <algorithm> defines a collection of…
Q: Write a function sumLength() that takes a list of strings as parameter, finds and returns the total…
A: A list is a collection that holds multiple data items using one variable. The values of the list can…
Q: Create a function that takes two numbers as arguments (num, length) and returns a list of multiples…
A: # As no language is mentioned, the program is written in Python language. def…
Q: (Note: Do not read input, instead use the arguments to the function. Do not print the output,…
A: Note: As any programming language is not mentioned in the question So I am using Python to write…
Q: program to be written in C Write a program that gets a list of integers from input, and outputs the…
A: It repeatedly swaps the adjacent elements if they are in the wrong order. First Pass: 5 1 4 2 8…
Q: Write a function called reverse_list that takes in a list and returns the reverse of the list. E.g.,…
A: The above question is solved in step 2 :-
Q: In loop_functions.py, define a function named list_concat that takes a single parameter li. This…
A: Reason for using FOR Instead of WHILE: This is because it is easier to use loops to iterate through…
Q: Write a function that receives two parameters, the first one is a list and the other is a string.…
A: Programming Language used: Python Source code in Python (Note: all necessary comments are included…
Q: O Write a function that takes a list and 2 integers x and y as parameter an the following: • If the…
A: I have written python code below:
Q: 1. Ask the user to input a phone number in the form "XXX-XXX-XXXX" 2. Use the functions above to…
A: print("Enter phone number as XXX-XXX-XXX") number = input("Type here: ") digitList = list(number)…
1) 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.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
- Ex1: a) Write a function for the user to enter a positive integer n with a value between 10 and 1000. If entered correctly, the function generates a list containing n random values that do not overlap between 1 and 5000 and the function returns the newly created list. Conversely, if entered incorrectly, the program will ask to re-enter until it is correct. Cases where n is considered incorrect:(i)- If the user enters a non-integer data type (like string, float, bool, ...)The program will display the error message 'Must enter a positive integer. Requires re-entry'.(ii)- If the input value is of the correct integer data type but the value is not in the range10 to 1000, the program gives the error 'Only values between 10 and 1000. Re-enter required'.Installation requirements: must use the try ... except statement to handle possible exceptionsin the program. b) Write a function that lists the amicable numbers in the list just created in a) (If there are no amicable numbers in the list,…Notice that all of the data in the inner lists are represented as strings. You are to write the function convert_data, which should make modifications to the inner lists according to the following rules: If and only if a string represents a whole number (ex: '3' or '3.0'), convert the string to an int. If and only if a string represents a number that is not a whole number (ex: '3.14'), convert the string to a float. Otherwise, leave the string as a str.HINT: The provided helper function is_number may be used (attached image). QUESTION: Complete the docstring below.def convert_data(data: List[list]) -> None: """Convert each string in data to an int if and only if it represents a whole number, and a float if and only if it represents a number that is not a whole number. >>> d = [['abc', '123', '45.6', 'car', 'Bike']] >>> convert_data(d) >>> d [['abc', 123, 45.6, 'car', 'Bike']] >>> d = [['ab2'], ['-123'], ['BIKES', '3.2'],…18) 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):
- 1 - Write a Python function that will do the following: 1. Ask the user to input an integer that will be appended to a list that was originally empty. This will be done 5 times, meaning that when the input is complete, the list will have five elements (all integers). a. Determine whether each element is an even number or an odd number b. Return a list of five string elements "odd" and "even" that map the indexes of the elements of the input list, according to whether these elements are even or odd numbers.For example: if the input sequence is 12, 13, 21, 51, and 30, the function will return the list ["even", "odd", "odd", "odd", "even"].10.20 LAB: Multiples of ten in a list Write a program that reads a list of integers, and outputs whether the list contains all multiples of 10, no multiples of 10, or mixed values. Define a function named is_list_mult10 that takes a list as a parameter, and returns a boolean that represents whether the list contains all multiples of ten. Define a function named is_list_no_mult10 that takes a list as a parameter and returns a boolean that represents whether the list contains no multiples of ten. Then, write a main program that takes an integer, representing the size of the list, followed by the list values. The first integer is not in the list. Ex: If the input is: 5 20 40 60 80 100 the output is: all multiples of 10 Ex: If the input is: 5 11 -32 53 -74 95 the output is: no multiples of 10 Ex: If the input is: 5 10 25 30 40 55 the output is: mixed values The program must define and call the following two functions. is_list_mult10() returns true if all integers in the list are…Python Programming - (Duplicate Elimination) Part 1: Create a function that receives a list and returns a (possibly shorter) list containing only the unique values in sorted order. Test your function with a list of numbers and a list of strings. Program is to also display results, that's the sorted list containing values. Part 2: Instead of hard coding the list passed to the sorting functions, request list values from user. (Hint: Request two lists from user, one containing values and another containing string.) Have the program eliminate duplicated values and display the lists (tasks required in part 1).
- complete the following function. // It is the same as observeCounter except that f has a parameter of type List[Counter] not Counter. // f will insist that the List[Counter] has length 3. // You must return a List[Int] not an Int. // The first element of the result List[Int] must correspond to the number of times that increment/decrement were called on the first element of type List[Counter], similarly for the second and third elements. def observeCounterList (f : List[Counter] => Unit) : List[Int] = { // TODO: Provide definition here. List (-1, -1, -1) }Write a function that takes list and a number (x) as parameters. Assume list contains only numbers, the function displays all of the numbers that are greater than x, and return true. If the function does not find any number greater than x, return your false which indicates an error.7. Assume you already have a list defined, called name, containing three strings: aperson’s first, middle, and last name, in that order. Write an expression that produces astring consisting of the person’s last name followed by a comma and space, then the firstname and a space, then the person’s middle initial followed by a period. So, for example,if name is equal to ['John', 'Phillip', 'Sousa'], your expression will produce the string'Sousa, John P.'
- Given both a list x and a tuple y, write a function called sum_list_andOr_tuple that sums all the elements of both data structures and returns the sum. There is also an optional boolean argument into the function called separate which, if True, causes the function to return the sum of the list and the tuple separately (returns two values); separate is False by default. Please note that the function DOES NOT print anything - it only returns a value(s). See the sample output below: >>> my_list = [0, 9, 99]>>> my_tuple = (8, 12)>>> result = sum_list_andOr_tuple(my_list, my_tuple)>>> print(result) Output: 128>>> result = sum_list_andOr_tuple(my_list, my_tuple, separate = True)>>> print(result) Output: 108, 201) - Write a Python function that will receive a list as an argument. A) The function will receive a list of at least 5 numbers as a single argument when the function is called. B)The function will ask the user to input a number and will find and return the index of that number in the list. C). If the number is not an element of the list, the function returns the string "unknown" and asks the user to try again. There can be a total of 3 possible failed trials, after which the program will return a message to the user and exit. Choose your own exit message.Write a function that concatenates all the strings in a list. The concatenation of all the strings in an empty list is the empty string "". please use Ocaml for the code and make sure the code is complete