Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # MAXIMUM FUNCTION FOR ALL NUMBERS IN A LIST WITH N ENTRIES
- num_list = [1, 4, 5, 100, "Text", 3.5, 23]
- def maxN(list):
- # Create a new list which only includes integers and floats from old list:
- list_num_only = [k for k in list if isinstance(k, float) or isinstance(k, int)]
- # Define the maximum of 2 numbers:
- def max(a, b):
- return (list_num_only[a] + list_num_only[b] + abs(list_num_only[a] - list_num_only[b])) / 2
- max_interim = 0
- for i in range(len(list_num_only)-1):
- max_interim = max(max(list_num_only[i], list_num_only[i+1]), list_num_only[i+2])
- return max_interim
- print(maxN(num_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement