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.
Program:
x=[] # list declaration
def maxList(x): # called function
highest=x[0] # Initially first element is considered as maximum
for i in range(0,len(x)): #Loop to find maximum
if x[i]>highest: # check maximum
highest=x[i]
return highest # return maximum
n=int(input("How many elements are in the list: ")) # Accept number of elements in the list
for i in range(0,n): #loop runs from 0 to n
b=int(input()) # accept an element
x.append(b) # append the element
print("Maximum element in the list is ",maxList(x)) # print highest
Output:
Write a function maxList that takes in a list of integers as argument and returns their...
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...
Write a function that takes a list as an argument and returns true if the list is already sorted in increasing order. (You should not sort the list, and make sure that you just iterate over the list once! Only one loop!) WRITE THE CODE IN PYTHON
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,...
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].
in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops
Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python
Write a function that takes, as an argument, a list of positive integers and a target value, and returns the number of times that the target value appears in the list. Call this function problem1(myList, target). For example, >>>problem1([1,2,3,4,5,6,5,4,3], 5) should return 2, and >>>problem1([1,2,3,4,5,6,5,4,3], 7) should return 0.
python 1. Write a function that takes in a string and returns the string sorted For example, "cat" becomes "act", "dog" becomes "dgo" Hint: You might need to use the functions join and sorted
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.
Write a function that takes an int as an argument and returns true if the int is an even number and false if not. In any case change the value of the original argument to twice its value. Use the integers 0 through 4 as test cases. Do not use any arrays.