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 num.
gt, lt, eq = find_gt_lt_eq(my_list, num = 3)
1)Python code:
#defining find_max_min function
def find_max_min(my_list):
#setting max and min as the first element
max,min=my_list[0],my_list[0]
#looping each element in the list
for i in my_list:
#checking if it is the max element
if(i>max):
#setting max as i
max=i
#checking if it is the min element
if(i
min=i
#returning tuple of max and min element
return((max,min))
#initializing a sample list
my_list=[1,2,3,4,5]
#calling find_max_min function
max,min=find_max_min(my_list)
#printing max and min
print(max,min)
Screenshot:
Output:
2)Python code:
#defining find_gt_lt_eq function
def find_gt_lt_eq(my_list,num):
#initialzing gt,lt,eq as 0
gt,lt,eq=0,0,0
#looping each item in list
for i in my_list:
#checking if it is greater than num
if(i>num):
#incrementing gt
gt+=1
#checking if it is less than num
elif(i
lt+=1
else:
#incrementing eq
eq+=1
#returning gt,lt and eq
return(gt,lt,eq)
#initialzing sample my_list
my_list=[1,2,3,4,5]
#calling find_gt_lt_eq and finding gt,lt,eq
gt,lt,eq=find_gt_lt_eq(my_list,num=3)
#printing gt,lt,eq
print(gt,lt,eq)
Screenshot:
Output:
write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple
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.
in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integers(2), and returns False otherwise. For example, contains_only_integers (3, 5, 17, 257, 65537) ), contains_only_integers( (-1,) ), and contains_only_integers( ) should all return True, but contains_only_integers (2.0,4.0)) and contains_only_integers (8, 4, "2", 1)) should both return false. Your function should use a while loop to do this calculation. 121 Hint: the is instance() built-in function provides the most...
Python homework Write a function called insert_value(my_list, value, insert_position) that takes a list, a value and an insert_position as parameters. The function returns a copy of the list with the value inserted into the list (my_list) at the index specified by insert_position. Check for the insert_position value exceeding the list (my_list) bounds. if the insert_position is greater than the length of the list, insert the value at the end of the list. if the insert_position is less than or equal...
Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set. For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...
Write a Python function that creates and returns a list of prime numbers between 2 and N, inclusive, sorted in increasing order. A prime number is a number that is divisible only by 1 and itself. This function takes in an integer and returns a list of integers.
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 The function longest that returns the longest of two strings. The function count_over that takes a list of numbers and an integer nand returns the count of the numbers that are over n. The function bmi that takes two parameters height and weight and returns the value of the body mass index: a person's weight in kg divided by the square of their height in meters. def longest(string1, string2): """Return the longest string from the two arguments, if the...
Python Write a move function that takes a list of tuples, where each tuple is an x-y-z coordinate pair. This function should update the original list in-place to shift/move/translate the coordinates by an x_move, y_move, and z_move (respectively) and return None.
Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...
IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].