Python
Write a function named minGap that takes in a list of integers and returns the minimum ‘gap’ between values in the list. The gap between two adjacent values in a list is defined as the second value minus the first value. For example, suppose we have the following list: [1, 3, 6, 7, 12] The first gap is between indices 0 and 1 and its value is 3 − 1 = 2. The second gap is 6 − 3 = 3. The smallest gap is 1, which is between indices 2 and 3.
def minGap(lst):
gap = None
for i in range(1, len(lst)):
if gap is None or lst[i] - lst[i - 1] < gap:
gap = lst[i] - lst[i - 1]
return gap
print(minGap([1, 3, 6, 7, 12]))
Python Write a function named minGap that takes in a list of integers and returns the...
1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
Write a Python function named print_nums that takes a single parameter, a list of float values, and prints out the list on a single line.enclosed in brackets, each value with three places after the decimal point, the values separated by two spaces. You do not have to provide comments for this code. Example 1: print_nums([3/3, 4/3, 573, 6/3]) prints: [1.000 1.333 1.667 2.000] Example 2: print_nums([3]) prints: [3.000] Example 3: print_nums([]) prints: []
In PYTHON: Write a function that receives a list of integers and returns the number of integers that are larger than the element immediately before them. For example, given [1,2,3,-5,0,-5,-10] the function should return 3 (since 1<2, 2<3, and -5<0).
Python: Write a function named "sort_by_average_rating" that takes a list/array of key-value stores as a parameter where each key-value store has keys "ratings", "budget", and "box_office" where budget and box_office are integers and ratings is a list of integers. Sort the input based on the average of the values in "ratings"
Write a Python script named assignment2.py that implements the following steps given an integer value: 1.) Double the value of every second digit beginning from the right. For example, the number 1386 has digits [1, 3, 8, 6] which become [2, 3, 16, 6]. 2.) Add the digits of the doubled values and the digits that were not doubled from the original number. For example, [2, 3, 16, 6] becomes 2 + 3 + 1 + 6 + 6 =...
Write a function maxList that takes in a list of integers as argument and returns their highest. You may not use the max() or the sorted() Python built-in functions.
Python. Write a function that takes in a list and returns the first nonzero entry. def nonzero(lst): """ Returns the first nonzero element of a list >>> nonzero([1, 2, 3]) 1 >>> nonzero([0, 1, 2]) 1 >>> nonzero([0, 0, 0, 0, 0, 0, 5, 0, 6]) 5 """ "*** YOUR CODE HERE ***"
Using Python, write a function named add_surname that takes as a parameter a list of first names. **It should use a list comprehension** to return a list that contains only those names that start with a "K", but with the surname "Kardashian" added to each one, with a space between the first and last names. For example, if the original list is: ``` ["Kiki", "Krystal", "Pavel", "Annie", "Koala"] ``` Then the list that is returned should be: ``` ['Kiki Kardashian',...
1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...