
ДЗ Пайтон Ввести список цілих чисел (з клавіатури або вручну в програмі) зайти максимальне та
мінімальне значення відсортувати список зробити зріз від елемента, номер якого введений користувачем до кінця списку порахувати середнє арифметичне цього зрізу * на 12 балів: зарандомити список :) (Сделайте пожалуйста на 12 балов)

Ответы на вопрос

Ответ:
from random import randint
lst = [randint(1, 100) for _ in range(15)]
print(f'Максимальне значення в списку {lst} дорівнює {max(lst)}')
print(f'Мінімальне значення в списку {lst} дорівнює {min(lst)}')
lst.sort()
fz = int(input('Зріз від якого елементу?\n')) - 1
lst = lst[fz:]
print(f'Середнє арифметичне зрізу {lst} дорівнює {sum(lst) / len(lst)}')
Объяснение:
з того що тут потрібно, напевно, це функції:
max - повертає найбільший елемент послідовності
min - повертає найменьший елемент послідовності
randint модуля random - повертає псевдовипадкове число в заданому діапазоні(ліва і права частина включно)



Task Description
The task requires the following steps to be performed on a list of integers: 1. Input a list of integers either from the keyboard or manually in the program. 2. Find the maximum and minimum values in the list. 3. Sort the list in ascending order. 4. Create a sublist starting from the element whose index is entered by the user until the end of the list. 5. Calculate the average of the sublist. 6. Randomize the list.Let's go through each step in detail.
Step 1: Input a List of Integers
To input a list of integers in Python, you can use the `input()` function to get user input and then split it into individual elements. Here's an example:```python numbers = input("Enter a list of integers (separated by spaces): ").split() numbers = [int(num) for num in numbers] ```
Alternatively, you can manually define the list in the program like this:
```python numbers = [1, 5, 3, 2, 4] ```
Step 2: Find the Maximum and Minimum Values
To find the maximum and minimum values in a list, you can use the `max()` and `min()` functions in Python. Here's an example:```python maximum = max(numbers) minimum = min(numbers) ```
Step 3: Sort the List
To sort the list in ascending order, you can use the `sort()` method of the list. Here's an example:```python numbers.sort() ```
Step 4: Create a Sublist
To create a sublist starting from a specific index until the end of the list, you can use list slicing. Here's an example where the index is entered by the user:```python index = int(input("Enter the index to start the sublist from: ")) sublist = numbers[index:] ```
Step 5: Calculate the Average of the Sublist
To calculate the average of a sublist, you can use the `sum()` function to get the sum of the sublist and then divide it by the length of the sublist. Here's an example:```python average = sum(sublist) / len(sublist) ```
Step 6: Randomize the List
To randomize the list, you can use the `random.shuffle()` function from the `random` module in Python. Here's an example:```python import random random.shuffle(numbers) ```
Putting it all together, here's an example that incorporates all the steps:
```python import random
numbers = input("Enter a list of integers (separated by spaces): ").split() numbers = [int(num) for num in numbers]
maximum = max(numbers) minimum = min(numbers)
numbers.sort()
index = int(input("Enter the index to start the sublist from: ")) sublist = numbers[index:]
average = sum(sublist) / len(sublist)
random.shuffle(numbers)
print("Maximum:", maximum) print("Minimum:", minimum) print("Sorted List:", numbers) print("Sublist:", sublist) print("Average of Sublist:", average) ```
Please note that the code provided above assumes valid input and does not include error handling.


Похожие вопросы

Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili