from random import randint
def loadInfoToFile():
f = open('результат.dat', 'w', encoding='utf-8')
name = input('Введите ваше имя: ')
randNums = [name]
for i in range(1000):
randNums.append(randint(1, 1000))
for i in randNums:
f.write(str(i) + '\n')
f.close()
return [i for i in randNums]
print(loadInfoToFile())
Результат на скрине
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')
from random import randint
def loadInfoToFile():
f = open('результат.dat', 'w', encoding='utf-8')
name = input('Введите ваше имя: ')
randNums = [name]
for i in range(1000):
randNums.append(randint(1, 1000))
for i in randNums:
f.write(str(i) + '\n')
f.close()
return [i for i in randNums]
print(loadInfoToFile())
Результат на скрине
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')