defmaximum_difference(generate_number_list): length=len(generate_number_list) for j inrange(0,length): max_index = j for i inrange(j+1,length): if generate_number_list[i]>generate_number_list[max_index]: max_index=i generate_number_list[j],generate_number_list[max_index]=generate_number_list[max_index],generate_number_list[j] return generate_number_list[0]-generate_number_list[length-1]
defmaximum_difference_with_builtin_operations(generate_number_list): iflen(generate_number_list) < 2: returnNone min_num = max_num = generate_number_list[0] for num in generate_number_list: min_num = min(min_num, num) max_num = max(max_num, num) return max_num - min_num
# [49, 97, 53, 5, 33, 65, 62, 51]
# [17, 72, 97, 8, 32, 15, 63, 97, 57, 60, 83, 48]
if __name__ == '__main__': # seed_value=int(input("Input a seed for the random number generator: ")) # element_number=int(input("How many elements do you want to generate? ")) try: seed_value = int(sys.stdin.readline().strip()) print("Input a seed for the random number generator: ",seed_value) except ValueError: print('Input is not an integer, giving up.') sys.exit() try: element_number = int(sys.stdin.readline().strip()) print("How many elements do you want to generate? ",element_number) except ValueError: print('Input is not an integer, giving up.') sys.exit() if element_number <= 0: print('Input should be strictly positive, giving up.') sys.exit() generate_number_list=generate_number(seed_value,element_number) print(f'The list is: {generate_number_list}') print(f'The maximum difference between largest and smallest values in this list is: {maximum_difference(generate_number_list)}') print(f'Confirming with builtin operations: {maximum_difference_with_builtin_operations(generate_number_list)}')