List info

def countSelf(arr): count = 0 for i in range(len(arr)): count = i + 1 return count def meanSelf(arr): mean = 0 for i in range(len(arr)): mean += arr[i] return mean / len(arr) def minSelf(arr): minimum = arr[0] before = "minimum is the first element" for i in range(len(arr)): if arr[i] < minimum: minimum = arr[i] if i != 0: before = arr[i - 1] return (minimum, before) def maxSelf(arr): maximum = arr[0] for i in range(len(arr)): if arr[i] > maximum: maximum = arr[i] return maximum def fourth(arr): if len(arr) >= 4: print("fourth element:", arr[3]) else: print("length of array < 4") def enterData(): array = [] while True: data = input("please enter digit: ") if data.isdigit(): if int(data) in array: print("array already have this digit") else: array.append(int(data)) print("current array", array) if data == "L" or data == "Leave": print(" ") if len(array) == 0: print("array length == 0, exiting...") else: print("count:",countSelf(array)) print("mean:", meanSelf(array)) print("minimum: ", minSelf(array)[0]) print("one before minimum: ", minSelf(array)[1]) print("maximum: ", maxSelf(array)) fourth(array) break if data == "R" or data == "Restart": print("program restarted") array = [] elif not data.isdigit(): print("only digits!") print("entering digits...") print("if you want to leave sycle and have results enter L or Leave") print("if you want to restart program enter R or Restart") enterData() input()

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.