1)Записать файл в файл ваше Имя 2) Создать массив из рандомных значений ( не менее 1000 элементов) и записать их все в файл 3) прочитать НА ПИТОНЕ ПОМОГИТЕ ПОЖАЛУЙСТАААААААА
timkafey
lines = [] with open('numbers.txt') as file: for line in file.readlines(): lines.append(line)
lines.pop(0)
dictionary = {}
with open('numbers.txt') as file: key = None value = None now = 1 for i in range(len(lines)): if now == 3: key = lines[i].replace('\n', '') elif now == 4: value = int(lines[i].replace('\n', ''))
if key != None and value != None: dictionary[key] = value
timkafey
lines = [] with open('numbers.txt') as file: for line in file.readlines(): lines.append(line)
lines.pop(0)
dictionary = {}
with open('numbers.txt') as file: key = None value = None now = 1 for i in range(len(lines)): if now == 3: key = int(lines[i].replace('\n', '')) elif now == 4: value = int(lines[i].replace('\n', ''))
if key != None and value != None and key >= 58 and value <= 500: dictionary[key] = value
Answers & Comments
from random import randint
name = 'your name'
with open('numbers.txt', 'w') as file:
file.write(name + '\n')
for line in [str(randint(1,100)) for _ in range(1000)]:
file.write(line + '\n')
fifty_eight = []
with open('numbers.txt') as file:
for line in file.readlines():
if line != name + '\n':
if int(line) == 58:
fifty_eight.append(58)
with open('fifty eight.txt', 'w') as file:
for _ in fifty_eight:
file.write('58\n')
with open('numbers.txt') as file:
for line in file.readlines():
lines.append(line)
lines.pop(0)
dictionary = {}
with open('numbers.txt') as file:
key = None
value = None
now = 1
for i in range(len(lines)):
if now == 3:
key = lines[i].replace('\n', '')
elif now == 4:
value = int(lines[i].replace('\n', ''))
if key != None and value != None:
dictionary[key] = value
if now == 4:
now = 1
else:
now += 1
print(dictionary)
ХРАНИ ТЕБЯ ГОСПОДЬ!))
with open('numbers.txt') as file:
for line in file.readlines():
lines.append(line)
lines.pop(0)
dictionary = {}
with open('numbers.txt') as file:
key = None
value = None
now = 1
for i in range(len(lines)):
if now == 3:
key = int(lines[i].replace('\n', ''))
elif now == 4:
value = int(lines[i].replace('\n', ''))
if key != None and value != None and key >= 58 and value <= 500:
dictionary[key] = value
if now == 4:
now = 1
else:
now += 1
print(dictionary)