sum_highest_five This function takes a list of numbers, finds the five largest numbers in the list, and returns their sum. If the list of numbers contains fewer than five elements, raise a ValueError with whatever error message you like. Sample calls should look like:
Q: Python: On-line Grocery Shopping Use grocery py in Canvas to start your program. It contains two…
A: Answer: Code: food = ["tomato_soup", "cheese", "sauce", "chicken"] stock = {"tomato_soup": 20,…
Q: You have been hired as an app developer for the company. The company plans to make an app for a…
A: Iterate over given list of order_items If item present in map, add its price to total Finally add…
Q: Assume that a variable named plist refers to a list with 12 elements, each of which is an int.…
A: Python statement for assigning a number to the list A variable named plist refers to a list with 12…
Q: If you have the following node declaration: struct Node { int number; struct Node * next; }; typedef…
A: C program to create all the required functions for the linked list.
Q: paython programing question Write a program that creates a list of N elements (Hint: use append()…
A: Note: Code comments have been added in the source code itself to have a better understanding of the…
Q: { int data;s struct Node *next; struct Node *prev; }; // Function to insert at the end…
A: // A complete working C++ program to // demonstrate all insertion methods #include…
Q: create_numbers_dictionary(numbers) which takes a list of integers as a Define a function called…
A:
Q: Inserting Nodes into the List: In the following code (The Code is written By C) : there are 3…
A: Link list in C is a data structure that do not store data in a contiguous manner. Elements are of…
Q: Program Three: Lists and Dictionaries Pizza3.py You need to copy Pizza2.py and make the following…
A: Inputs function to input the data from the user Processing function to process the orders Outputs…
Q: Given snippet code below that you are required to complete. You are not allowed to make a new…
A: #include <stdio.h>#include <conio.h>#include <malloc.h>struct node {int key;struct…
Q: etween equally spaced X coordinates. Create a list of equally spaced X coordin. *a based on the…
A: I have written the PYTHON code below:
Q: Use C language only. Create a program that will ask for Enter number of students: (for this…
A: Summary: In this question, we have been given one program, in that program, there are three…
Q: Capital Quiz Write a program that creates a map containing the U.S. states as keys, and their…
A: Given:
Q: 1. count_perfect_squares This function takes a single argument, nums , Which is a list of numbers.…
A: Start import math def count_perfect_squares(nums): then count =0 if int(root + 0.5) ** 2…
Q: 5. Declare a set named vowels containing the strings 'a','e','i','o', 'u'. Create a function called…
A: As per Bartleby's policy, only 1st question can be solved for multiple questions. Please post the…
Q: Use Python programming. When analyzing data sets, such as data for human heights or for human…
A: - We are given with the input as the number n - Then n elements are inputed in the list and we have…
Q: 3. A list of numbers is considered increasing if each value after the first is greater than or equal…
A: Answer
Q: Create a function called find_big_words . The function should accept a list as a parameter. Parts…
A: A list is a type of collection in Python along with tuples and dictionaries. A list can have…
Q: If you have the following node declaration: struct Node { int number; struct Node * next; }; typedef…
A: According to the policy, only the first 3 questions has been answered. The remaining questions can…
Q: You have been hired as an app developer for the company. The company plans to make an app for a…
A: According to the Question below the Solution: Program Output:
Q: Python Code: Use def functions. Please upload the code. Thank you. Stop when and only when the…
A: ANSWER:-
Q: This assignment requires the main function and a custom value-returning function. The…
A: random.randint(200,250) : function imported using "import random" module, returns a random number…
Q: In this lab we will create three functions. The first will be called main. Main will simply be the…
A: Python used to answer this question
Q: You have been hired as an app developer for the company. The company plans to make an app for a…
A: In python list is a data structure that is used for storing multiple data values in a single…
Q: Common Time Zones Function Name: commonTimeZones() Parameters: code1( str ) , code2( str )…
A: Hey there, I am writing the required solution of the questin mentioned above. Please do find the…
Q: Laboratory Exercise No. 40 Filename: Lab_exer40 You are tasked to create a program that will get the…
A: Required: Laboratory Exercise No. 40 Filename: Lab_exer40 You are tasked to create a program…
Q: rite a procedure (intercalate sep lst) where sep is a string and lst s a list of strings that…
A: Python code :- sep=("I","Love","functional","programming")x=" ".join (sep)print (x)…
Q: PS: Do not use regular expressions or built in function. Please answer it according to the…
A: Python code: def operateList(A, n): even = [] odd = [] for i in range(n): if ((i % 2) == 0):…
Q: struct Node { int data; Node • next; }; Node • head; a. Write a function named addNode that takes in…
A: Step 1: Declare structure with data and next member Step 2: Accept choice from user, 1 for add node,…
Q: Dictionary-Returned Function a) Define a function, dictSqrt() with a parameter, x: 1) Create a…
A: Here, we have to write a python program for the given problem.
Q: Inserting Nodes into the List: In the following code (This is Code By C) : there are 3 functions :…
A: Step 1:- Program Approach:- 1.Add the two functions to the given code:- a)insert_last // insert…
Q: A teacher stores the most recent quiz scores for her class in the list scores. The first element in…
A: GIVEN: A teacher stores the most recent quiz scores for her class in the list scores. The first…
Q: Write a function frequency_match(text, chars) that receives a string text and a dictionary chars…
A: The required Python code: def frequency_match(text, chars): # function return list for word in…
Q: If you have the following node declaration: struct Node { int number; struct Node * next; }; typedef…
A: Struct node:- A node is a struct with at least a data field and a reference to a node of the same…
Q: def create_category(info): li = info.split() if len(li) == 2: if is_numeric(li[1])…
A: Hello student, hope you are doing good. The python code is given, we need to debug the code to find…
Q: #include using namespace std; struct Node { int data; struct Node *next; }; struct Node* head…
A: In doubly linked list is one in which all nodes are linked together by multiple no.of links. A…
Q: Inserting Nodes into the List: In the following code (The Code is written By C) : there are 3…
A: Code :- #include<stdio.h> #include<stdlib.h> struct node { int data;…
Q: program7.py This assignment requires the main function and a custom value-returning function. The…
A: Custom function fun7(): Takes a list of random integers as its argument A loop is used to iterate…
Q: Sample run Your program must define and use the following functions only: 1. read(): reads the city…
A: the code is an given below : def read(): cities = [] tempAvg = [] n =…
Q: If you have the following node declaration: struct Node { int number; struct Node * next; }; typedef…
A: Program code: #include <stdio.h> #include <stdlib.h> //struct store linked list node…
Q: 2. ID: A Name: 2. A list of numbers is considered increasing if each value after the first is…
A: List: List is used to store a collection of similar data types. List items is written in square…
Q: create_names_dictionary(initials_list, names_list) which takes a list of initials and a list of…
A: I give the code in Python along with output and code screenshot
Q: replaceNumbers function receives a list of integer numbers. The function replaces all even numbers…
A: The program is written in Python. Check the program screenshot for the correct indentation. Please…
Q: 5. Dictionary-Returned Function a) Define a function, dictSqrt0 with a parameter, x: 1) Create a…
A: Q: Use zip and dict to create a dictionary
Q: is Valid Phone Number(): ReturnsTrue if the provided phone number (represented as a string) is…
A: Actually, python is a easiest programming language. It has a concise(less) code.
Q: A teacher stores the most recent quiz scores for her class in the list scores. The first element in…
A: A teacher stores the most recent quiz scores for her class in the list scores. The first element in…
Q: def recdif(lst): PRE: 1st is a list of 2 or more integers POST: returns the greatest absolute…
A: def recdif(lst): n = len(lst) if n <= 1: return 0 x = int(n/2) return…
Q: 17. The following function takes a parameter that is a list of integers; the list has at least one…
A: The code given in question is: def findLarge(intlist): largest = 0 pos = 0 for i in range(1,…
Q: Define a function named build_dictionary (words_list) that takes a list of words as a parameter. The…
A: Here I have defined the function named build_dictionary(). Inside the function, I have created an…
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…
6. sum_highest_five
This function takes a list of numbers, finds the five largest numbers in the list, and returns their sum. If the list of numbers contains fewer than five elements, raise a ValueError with whatever error message you like.
Sample calls should look like:
>>> sum_highest_five([10, 10, 10, 10, 10, 5, -17, 2, 3.1])
50
>>> sum_highest_five([5])
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "<pyshell#44>", line 1, in <module>
File "/homework/final.py", line 102, in sum_highest_five
raise ValueError("need at least 5 numbers")
ValueError: need at least 5 numbers
Trending now
This is a popular solution!
Step by step
Solved in 3 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,…program7.pyThis assignment requires the main function and a custom value-returning function. The value-returning function takes a list of random integers as its only argument and returns a smaller list of only the elements that end with 7. This value-returning function must use a list comprehension to create this smaller list.In the main function, code these steps in this sequence: Set random seed to 42 import randomrandom.seed(42) create an empty list that will the hold random integers. use a loop to add 50 random integers to the list. All integers should be between 200 and 250, inclusive. Duplicates are okay. sort the list in ascending order and then use another loop to display all 50 sorted integers on one line separated by spaces. print a slice showing list elements indexed 5 through 10, inclusive. print a second slice showing the final 5 elements in the sorted list. execute the custom function with the entire…program7.pyThis assignment requires the main function and a custom value-returning function. The value-returning function takes a list of random integers as its only argument and returns a smaller list of only the elements that end with 7. This value-returning function must use a list comprehension to create this smaller list.In the main function, code these steps in this sequence: Set random seed to 42 import randomrandom.seed(42) create an empty list that will the hold random integers. use a loop to add 50 random integers to the list. All integers should be between 200 and 250, inclusive. Duplicates are okay. sort the list in ascending order and then use another loop to display all 50 sorted integers on one line separated by spaces. print a slice showing list elements indexed 5 through 10, inclusive. print a second slice showing the final 5 elements in the sorted list. execute the custom function with the entire original list as its sole argument. report the number of elements in…
- 1. Write a function called `CleanString` that takes one argument, an accounting number formatted as a string, and returns the number as a float. For example, if the argument is the string '$(7,074,619)', the return value should be the float -7074619. This function should be created in the first code cell below. 2. Iterate over the list `data` and "apply" the function `CleanString` to each element of the list. Save the result to a new list, `cleandata` (this iterating should be completed in the second code cell below).Return Growing NumList This function will be given a single number, it should return a list of strings of numbers. Each string in the list will only contain a single number repeated an arbitrary amount of times. The number each string will contain will be equal to the current string's index+1. The number in the string should be repeated the same number of times as the string's index+1. Each number in the string should be separated by a space. This list should stop when its size equals the max number specified. Signature: public static ArrayList<String> returnGrowingNumList(int max) Example: INPUT: 3OUTPUT: [1, 2 2, 3 3 3] INPUT: 6OUTPUT: [1, 2 2, 3 3 3, 4 4 4 4, 5 5 5 5 5, 6 6 6 6 6 6]PLEASE HELP IN FUNCTIONAL PROGRAMMING CODE I have to insert a few lines to generate random numbers and for determining the time taken to get results (define (insert L M) (if (null? L) M (if (null? M) L (if (< (car L) (car M)) (cons (car L) (insert (cdr L) M)) (cons (car M) (insert (cdr M) L)))))) ;; Exp. (insertionsort '(4 2 10 3 -1 5)) ==> (-1 2 3 4 5 10) (define (insertionsort L) (if (null? L) '() insert (list (car L)) (insertionsort (cdr L))))) (define (random-list n) (unless (exact-nonnegative-integer? n) (raise-argument-error 'make-list "exact-nonnegative-integer?" 0 n)) (let loop ([n n] [r '()]) (if (zero? n) r (loop (sub1 n) (cons (random 2147483647) r))))) Sample function call:(insertionsort (random-list 10000))
- Define the function (siftNum lst). This function should resolve to all the numbers in the list, lst. For example: (siftNum '(a 8 2 1 m l 90 p 2)) resolves to '(8 2 1 1 90 2).program7.pyThis assignment requires the main function and a custom value-returning function. The value-returning function takes a list of random integers as its only argument and returns a smaller list of only the elements that end with 7. This value-returning function must use a list comprehension to create this smaller list.In the main function, code these steps in this sequence: create an empty list that will the hold random integers. use a loop to add 50 random integers to the list. All integers should be between 200 and 250, inclusive. Duplicates are okay. sort the list in ascending order and then use another loop to display all 50 sorted integers on one line separated by spaces. print a slice showing list elements indexed 5 through 10, inclusive. print a second slice showing the final 5 elements in the sorted list. execute the custom function with the entire original list as its sole argument. report the number of elements in the new "sevens" list returned by the custom…•is Valid Phone Number(): ReturnsTrue if the provided phone number (represented as a string) is cor-rectly formatted, otherwiseFalse. To be considered correctly formatted, phone numbers must bewritten as###-###-####, where#is a digit between 0 and 9 .•validatePhoneBook(): A phone book is a list where each entry is a phone book record (represented asa dictionary; see below for more details). This function checks each phone book record in the phonebook for correctly formatted phone numbers.A phone book record is a dictionary which initially has two keys: the key"name"mapped to thecontact’s name (string) and the key"phone number"mapped to that contact’s phone number (alsoa string).validatePhoneBook()adds a new key"valid"to the record with the valueTrueif the phonenumber is formatted correctly, otherwiseFalse. 1. Write white-box and black-box tests for the function is ValidPhoneNumber(). You should do this with-out Python, either on paper, or in a simple document. Don’t worry about…
- This code is a part of a C dictionary. Please write the code for the below requirements. dict_get Next, you will implement: char* dict_get (const dict_t* dict, const char* key); This function goes through the list given by dict. If you use the above structure, this means starting at el = dict->head and checking each time whether the key at el is key; if it is not, we set el = el->next, until either key is found, or we reach el == NULL. To compare key with el->key, we need to compare one by one each character in key with those in el->key. Remember that strings in C are just pointers (memory addresses) to the first character in the string, so comparing el->key == key will not do what you want. So how do you even get the length of a string s? You would start at memory location s and advance as long as the byte at s (i.e. *s) is not the end-of-string marker (\0, the NULL character). This can get a bit messy, so luckily, you are allowed to use the string comparison…Contact list: Binary Search A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Frank 867-5309 Joe 123-5432 Linda…Use the function design recipe to develop a function named count_odds. The function takes a list of integers, which may be empty. The function returns the number of odd integers in the list. Automated testing is required Your solutions can use:• the [] operator to get and set list elements (e.g., lst[i] and lst[i] = a)• the in and not in operators (e.g., a in lst)• the list concatenation operator (e.g., lst1 + lst2)• the list replication operator (e.g., lst * n or n * lst)• Python's built-in len, min and max functions, unless otherwise noted.Your solutions cannot use:• list slicing (e.g., lst[i : j] or (lst[i : j] = t)• the del statement (e.g., del lst[0])• Python's built-in reversed and sorted functions.• any of the Python methods that provide list operations, e.g., sum, append, clear, copy, count, extend, index, insert, pop, remove, reverse and sort• list comprehensions