Python 文件行查看器
我非常困惑,请帮忙,谢谢。我不知道如何以正确的方式编写这段代码。
编写一个程序,询问用户文件的名称。该程序应该读取所有 将文件的数据放入列表中并显示文件包含的数据行数,以及 然后要求用户输入他们想要查看的行号。该计划 应显示指定行。程序应通过以下方式处理以下异常 显示错误消息:
• 找不到指定的文件名时引发的 IOError 异常或 打开。 • 当以行形式给出非整数值时引发 ValueError 异常 数字。 • 当行号超出范围时引发的 IndexError 异常 数据列表。
I am super confused could use some help please, thank you. I don't know how to write this code the right way.
Write a program that asks the user for the name of a file. The program should read all of
the file’s data into a list and display the number of lines of data that the file contains, and
then ask the user to enter the number of the line that they want to view. The program
should display the specified line.The program should handle the following exceptions by
displaying an error message:
• IOError exceptions that are raised when the specified filename cannot be found or
opened.
• ValueError exceptions that are raised when a non-integer value is given as a line
number.
• IndexError exceptions that are raised when the line number is outside the range of
the data list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论