Вопрос задан 13.11.2023 в 01:26. Предмет Информатика. Спрашивает Голуб Оля.

Треба створити проекти мовою Python, дуже терміново!! Задача 1. Дано масив з цілих чисел. Знайти

суму чисел, які більше за число f.Задача 2. Знайдіть середнє арифметичне від'ємних значень елементів одновимірного масиву, всі елементи якого є дійсними числами.​
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Сащеко Соня.

Ответ:

1.

def знайти_суму_більше_за_f(масив, f):

сума = 0

for число in масив:

if число > f:

сума += число

return сума

масив = [1, 2, 3, 4, 5, 6]

f = 3

результат = знайти_суму_більше_за_f(масив, f)

print(результат)

2.

масив = [-2, -5, -7, 8, -3, 10, -12]

сума = 0

кількість_відємних = 0

for елемент in масив:

if елемент < 0:

сума += елемент

кількість_відємних += 1

if кількість_відємних > 0:

середнє_відємних = сума / кількість_відємних

print("Середнє арифметичне від'ємних значень:", середнє_відємних)

else:

print("У масиві немає від'ємних елементів.")

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Task 1: Finding the sum of numbers greater than a given number

To find the sum of numbers in an array that are greater than a given number, you can follow these steps in Python:

1. Initialize a variable `sum_numbers` to 0. This variable will store the sum of numbers greater than `f`. 2. Iterate through each element in the array. 3. Check if the current element is greater than `f`. 4. If it is, add the current element to `sum_numbers`. 5. After iterating through all the elements, the value of `sum_numbers` will be the sum of numbers greater than `f`.

Here's an example implementation:

```python def sum_numbers_greater_than_f(array, f): sum_numbers = 0 for num in array: if num > f: sum_numbers += num return sum_numbers ```

You can use this function by passing in your array and the value of `f`. The function will return the sum of numbers greater than `f`.

Task 2: Finding the average of negative values in a one-dimensional array

To find the average of negative values in a one-dimensional array, you can follow these steps in Python:

1. Initialize variables `sum_negative` and `count_negative` to 0. `sum_negative` will store the sum of negative values, and `count_negative` will keep track of the number of negative values. 2. Iterate through each element in the array. 3. Check if the current element is negative. 4. If it is, add the current element to `sum_negative` and increment `count_negative` by 1. 5. After iterating through all the elements, calculate the average by dividing `sum_negative` by `count_negative`.

Here's an example implementation:

```python def average_negative_values(array): sum_negative = 0 count_negative = 0 for num in array: if num < 0: sum_negative += num count_negative += 1 if count_negative == 0: return 0 # To avoid division by zero if there are no negative values average = sum_negative / count_negative return average ```

You can use this function by passing in your array. The function will return the average of negative values in the array.

I hope this helps! Let me know if you have any further questions.

0 0

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

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

Последние заданные вопросы в категории Информатика

Задать вопрос