【发布时间】:2020-05-28 10:13:30
【问题描述】:
该程序必须分析学生编号,如果正确,则将其写入一个list,如果不正确,则将其写入另一个list。如果它们有八位数字并且只包含数字,则它们是正确的。
但是,当涉及到 try 和 except 部分时,我不知道该输入什么。
如果有人可以提供帮助,我将不胜感激!
Valid_file = "ValidNumbers.txt"
Invalid_file = "InvalidNumbers.txt"
Data_file = "Data.txt"
def analyse_students(Data_file):
lenth = len(Data_file)
total = 0
try:
except:
return 0
def read(Data_file):
count = 0
student_list = []
try:
open(Data_file)
except:
print("Couldn't append file", Valid_file)
return count, student_list
def write(student, status):
if status:
try:
open(Data_file)
except:
print("Couldn't append file", Invalid_file)
count, student_list = read(Data_file)
print("Number of lines read", count)
for student in student_list:
print("See output files")
【问题讨论】:
-
你是什么意思
i however have no idea what to type when it comes to the try except part -
你遇到了什么错误?语法错误 try-except 还是没有得到想要的结果?
-
我没有收到错误它什么也不做。我只是不知道要输入什么才能使程序正常工作。 data_file 包含我需要排序的一组数字,但我不知道如何测试,以便可以将这些数字发送到它们各自的列表。
-
您需要使用上下文管理器才能写入或打开文件。