Составьте программу которая создает файл из N элементов типа integer

22 Сен 2019 в 06:42
200 +1
0
Ответы
1

Sure! Here is an example program in Python that creates a file with N elements of type integer:

N = 10
# Generate N random integers
import random
integers = [random.randint(1, 100) for _ in range(N)]
# Write integers to a file
with open('integers.txt', 'w') as file:
for num in integers:
file.write(str(num) + '\n')
print(f"File with {N} integers has been created.")

In this program, we first specify the value of N which is the number of elements we want in the file. We then generate N random integers using a list comprehension. Finally, we open a file called integers.txt in write mode and write each integer to the file, one integer per line.

After running this program, you will have a file named integers.txt containing N integers.

19 Апр в 20:22
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Название заказа не должно быть пустым
Введите email
Бесплатные доработки
Гарантированные бесплатные доработки
Быстрое выполнение
Быстрое выполнение от 2 часов
Проверка работы
Проверка работы на плагиат
Интересные статьи из справочника
Поможем написать учебную работу
Название заказа не должно быть пустым
Введите email
Доверьте свою работу экспертам
Разместите заказ
Наша система отправит ваш заказ на оценку 84 028 авторам
Первые отклики появятся уже в течение 10 минут
Прямой эфир