Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import random
- import sys
- def Bubble_Sort(list_to_sort):
- for i in range (len(list_to_sort), 0, -1):
- for j in range(1, i):
- if list_to_sort[j-1] > list_to_sort[j]:
- temporary_number = list_to_sort[j-1]
- list_to_sort[j-1] = list_to_sort[j]
- list_to_sort[j] = temporary_number
- return list_to_sort
- def Arithmetic_Mean(list_to_calculate):
- average = 0
- for i in list_to_calculate:
- average += i
- average /= len(list_to_calculate)
- return round(average, 2)
- def Median_Value(list_to_calculate):
- if (len(list_of_numbers) % 2 == 0):
- first_index = int (len(list_of_numbers) / 2)
- second_index = int (len(list_of_numbers) / 2 - 1)
- median = (list_of_numbers[first_index] + list_of_numbers[second_index]) / 2
- return round(median, 2)
- else:
- index = int ((len(list_of_numbers) - 1) / 2)
- median = list_of_numbers[index]
- return round(median, 2)
- try:
- amount_of_numbers = int(input("Введите число элементов списка: "))
- except ValueError:
- sys.exit("Количество элементов — натуральное значение!")
- list_of_numbers = []
- for i in range (amount_of_numbers):
- list_of_numbers.append(round(random.uniform(0, 50), 2))
- print("Исходный список:")
- for i in list_of_numbers:
- print(i, end = " ")
- list_of_numbers = Bubble_Sort(list_of_numbers)
- print("\nОтсортированный список:")
- for i in list_of_numbers:
- print(i, end = " ")
- print ("\nСреднее арифметическое:", Arithmetic_Mean(list_of_numbers))
- print ("Медиана:", Median_Value(list_of_numbers))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement