张冯的小能豆 发表于 2020-4-2 23:59:06

甲鱼这个问题够可以,想了老长时间,刚想出来

本帖最后由 张冯的小能豆 于 2020-4-3 00:03 编辑

不管怎样,还是把自己感动了,得发个帖子庆祝一下,我知道这个有很多不完美,有很多需要优化的地方,哎呀,其实对我来讲,我能把这个写出来已经很开心了,要是大家有更好的建议我更开心。加油!
def print_hang(file,hang):
    i = 0

    print('文件从%s到%s的内容如下:'%(count1,count2))
    l = open(file,'r')
    for each_line in l:
      i += 1
      if i in count:
            print(each_line)
    l.close()





f = input('请输入要打开的文件:')
h = input('请输入需要显示该文件的前几行:')
cut = h.split(':')
if cut == '':
    if cut == '' and cut =='':
      count1 = '开始'
      count2 = '末尾'
      count = range(0,100)
    else:
      count1 = '开始'
      count2 = int(cut) + 1
      count = range(count2)
elif cut == '':
    count1 = int(cut)
    count2 = '末尾'
    count = range(count1,100)
else:
    count1 = str(cut)
    count2 = str(cut) + 1
    count = range(count1,count2)

count1 = str(count1)
count2 = str(count2)
print_hang(f,h)





还是很开心

weiter 发表于 2020-4-4 12:32:03

加油!{:10_333:}
页: [1]
查看完整版本: 甲鱼这个问题够可以,想了老长时间,刚想出来