Предмет: Информатика, автор: princealikosh

задание 1 1. Создайте одномерный массив из 20 случайных чисел, принадлежащих интервалу (-10,10). Поменяйте местами максимальный элемент массива с минимальным. Вывести: - исходный массив - минимальный элемент и его номер - максимальный элемент и его номер - массив после перестановки
задание 2 Создайте двумерный массив из 8 строк и 6 столбцов, заполните его случайными числами из интервала (-10, 35). Замените все элементы, значение которых больше 15 на номер строки, в которой он находится. Выведите преобразованный массив.​

Ответы

Автор ответа: MagicSticks
1

1.
import random

# Создаем массив из 20 случайных чисел в интервале (-10, 10)

arr = [random.randint(-10, 10) for _ in range(20)]

print("Исходный массив:", arr)

# Находим минимальный и максимальный элементы и их индексы

min_idx = 0

max_idx = 0

for i in range(len(arr)):

   if arr[i] < arr[min_idx]:

       min_idx = i

   if arr[i] > arr[max_idx]:

       max_idx = i

# Меняем местами минимальный и максимальный элементы

arr[min_idx], arr[max_idx] = arr[max_idx], arr[min_idx]

# Выводим результаты

print("Минимальный элемент:", arr[min_idx], "на позиции", min_idx)

print("Максимальный элемент:", arr[max_idx], "на позиции", max_idx)

print("Массив после перестановки:", arr)

----------------------------------------------------------------------------------------------------------

2.

i
mport random

# создаем двумерный массив

rows = 8

cols = 6

arr = [[random.randint(-10, 35) for j in range(cols)] for i in range(rows)]

# заменяем все элементы, значение которых больше 15, на номер строки

for i in range(rows):

   for j in range(cols):

       if arr[i][j] > 15:

           arr[i][j] = i

# выводим преобразованный массив

for i in range(rows):

   for j in range(cols):

       print(arr[i][j], end=' ')

   print()

Похожие вопросы
Предмет: Английский язык, автор: nikomasha207
Предмет: Математика, автор: pkiraua
Предмет: Английский язык, автор: laramahutova28
Read the text "Surf's up!"

 



 

Surfing is popular all over the world. It's practised on lakes and rivers, seas and oceans — anywhere with good wind.

 

Some people think that it's a new kind of sport. But it is not. It was first reported by the British explorer Captain Cook in 1778. It became popular with the introduction of mass-produced, lightweight boards made of fibreglass in the 1960s. The birthplace of surfing is Hawaii and today it's home of the most famous surfing competition. Huge waves crash along mile after mile of beautiful sand, and every surfer dreams of experiencing surfing in Maui or Oahu.

 

The best time for surfing is when the waves are high. Serious surfers must be very brave, love adventure and have lots of energy. Once they've experienced the excitement of a ride on top of the waves, they never want to stop.

 

It takes time to learn to catch a wave at the right moment, stand up on your board and stay there. But during a hot summer day, who minds practising?

  

Сhoose the right sentence:

 

1.  

It was first reported by the British explorer Captain Cook in 1728.

It was first reported by the British explorer Captain Cook in 1798.

It was first reported by the British explorer Captain Cook in 1778.

 

2. 

Huge waves crash along mile after mile of beautiful sand, and every surfer dreams of experiencing surfing in Maui or Oahu.

Huge waves crash along mile after mile of beautiful sannd, and every surferes dreams of experiencing surfing in Maui or Oahu.

Huge waves crash along miles after mile of beautiful sand, and every surfer dreams of experincing surfing in Maui or Oahu.

 

3. 

It takes time to learn to catched a wave at the right moment, stand up on your board and stay there.

It takes time to learn to catch a wave at the right moment, stand off on your board and stay there.

It takes time to learn to catch a wave at the right moment, stand up on your board and stay there.

Предмет: Математика, автор: Аноним