标签:spl list nes while ftime for code pac 输入
with open(‘data1_1.txt‘, ‘r‘, encoding = ‘utf-8‘) as f:
data=f.readlines()
n = 0
for line in data:
if line.strip(‘\n‘) == ‘‘:
continue
n+=1
print(f‘共{n}行‘)
with open(‘data1_1.txt‘, ‘r‘, encoding = ‘utf-8‘) as f:
n = 0
for line in f:
if line.strip(‘\n‘) == ‘‘:
continue
n += 1
print(f‘共{n}行‘)
with open(‘data1_2.txt‘, ‘r‘, encoding = ‘utf-8‘) as f:
n = 0
for line in f:
if line.strip() == ‘‘:
continue
n += 1
print(f‘共{n}行‘)
with open(‘data1_2.txt‘, ‘r‘, encoding = ‘utf-8‘) as f:
n = 0
for line in f:
if line.isspace():
continue
n += 1
print(f‘共{n}行‘)
with open(‘data2.txt‘, ‘r‘, encoding = ‘utf-8‘) as f:
data = f.read().split(‘\n‘)
unique_line = []
for line in data:
if data.count(line) == 1:
unique_line.append(line)
print(f‘共{ len(unique_line) }独特行‘)
for i in unique_line:
print(i)
task6
import random
i=0
list=[]
a=int(input(‘输入随机抽点人数:‘))
with open(‘lucky.txt‘, ‘w‘) as f:
f.close()
with open(‘data7.txt‘, ‘r‘) as f:
data=f.readlines()
while i<a:
x=random.randint(1,80)
b=data[x]
print(b)
list.append(b)
i+=1
with open(‘lucky.txt‘, ‘w‘) as f:
for i in list:
f.write(i)
import random
import datetime
t=datetime.datetime.now()
datetime=t.strftime(‘%Y%m%d‘)
i=0
list=[]
a=int(input(‘输入随机抽点人数:‘))
with open(datetime+‘.txt‘, ‘w‘) as f:
f.close()
with open(‘data7.txt‘, ‘r‘) as f:
data=f.readlines()
while i<a:
x=random.randint(1,80)
b=data[x]
print(b)
list.append(b)
i+=1
with open(datetime+‘.txt‘, ‘w‘) as f:
for i in list:
f.write(i)
标签:spl list nes while ftime for code pac 输入
原文地址:https://www.cnblogs.com/czp666/p/14779074.html