求大佬帮忙 语法错误问题
课后作业29讲文件第三题错误名称invaild syntax,错误标注点在else下面的for之前
个人尝试把else那段代码直接删除把最后一个elif直接改成else可以正常运作
但加上之后就会报错,由于格式内容几乎一样,左思右想不明白是哪里报错
实在想不通来求助大佬帮助,帮帮孩子,非常感谢。
a = input("请输入要打开的文件地址:")
b = input("请输入要打显示前几行:")
f = open(a)
if b ==":":
print("文件",a,"的全文内容如下")
for i in f:
print(i)
elif b ==":":
g = int(b.split(":"))
print("文件",a,"从开始到第",g,"行内容如下")
for i in f:
if g:
g -=1
print(i)
elif b ==":":
g = int(b.split(":"))
print("文件",a,"从第,",g,"行到结束的内容如下")
for i in f:
g -=1
if g <= 0:
print(i)
else:
g = int(b.split(":"))
n = int(b.split(":"))
print("文件",a,"从第",g,"行到第,"n,"行内容如下")
for i in f:
g -=1
if g <=0 and n:
n -=1
print(i) 补充一下使用的python版本是3.9.0不知道是否有关系,我觉得应该没啥关系,万一呢。{:10_245:} print("文件",a,"从第",g,"行到第,",n, "行内容如下")
n前面少个逗号 lirenbing01 发表于 2020-11-23 15:44
n前面少个逗号
谢谢。。头脑发胀感觉自己凉了
页:
[1]