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

Я новичок в Python. Как можно заполнить матрицу по определенному общему условию,когда заполняется только 1 и 3 строка нулями. Размер 5*5?
from random import random
a = []
for i in range(5):
z = []
for j in range(5):
n = int(random() * 2)
z.append(n)
print("%3d" % n, end='')
print()
a.append(z)
print()


restIess: а что ваш код делает?
Tom126666: он заполняет случайным образом две строки
Tom126666: мне надо чтобы только заполнилась 1 и 3 строка
Tom126666: можно без random
restIess: надо заполнить 2,4,5 строки случайными числами, а 1 и 3 нулями?
restIess: а что с остальными строками то делать?
Tom126666: Задан двухмерный массив 5*5 элементов. Какому общему условию удовлетворяют все заштрихованные элементы ( 1 и 3 строка заштрихована)
Tom126666: индексация начинается с 0 от верхней левой ячейки
Tom126666: Я так думаю , что заштрихованные элементы - это 0
restIess: Ответ глянь

Ответы

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

Будем вести отсчет от единицы

a = [[0]*5,[],[0]*5,[],[]]

for i in range(len(a)):

   for j in range(len(a[i])):

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

   print()

Ну а если идём от 0 до 4

a = [[],[0]*5,[],[0]*5,[]]

for i in range(len(a)):

   for j in range(len(a[i])):

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

   print()


Tom126666: Огромное спасибо, проверю в Питоне. Если будут вопросы к Вам можно обратиться. В основном программирую на Паскале
restIess: Конечно, можно)
Tom126666: Еще раз спасибо
Похожие вопросы
Предмет: Английский язык, автор: Димасик17
ПОЖАЛУЙСТА!! Срочно!!
НАПИШИТЕ как читается текст ,произношения на английском

The problem
of learning foreign languages is very important today. Students should learn
foreign languages. They became important especially at the present time.
Foreign languages are needed as the main and most efficient means of
information exchange between the people of our planet.

Today
English is the language of the world. Over 350 million people speak it as a
mother tongue. The native speakers of English live in Great Britain, in the
United States of America, Australia and New Zealand. English is one of the
official languages in the Irish Republic, Canada and South African Republic. As
a second language it is used in the former British and US colonies.

It is the
major international language for communication in such areas as science,
technology, business and mass media. English ought to be used as one of the
official languages of the United Nations Organisation and other political
organisations. It is the language of computer software, literature, education,
modern music, international tourism.

Learning a
foreign language is not an easy thing. It is a long and slow process that takes
a lot of time and patience. But every educated person, every good specialist
has to know English because it is absolutely necessary nowadays.

It is well
known that reading books in the original, talking with the English speaking
people will help a lot. When learning a foreign language you are to learn the
culture and history of the native speakers. You may any foreign
language. They are all important.
Предмет: Математика, автор: ольга1757