【发布时间】:2015-10-23 15:56:56
【问题描述】:
def open_file():
data=open("data_full.txt")
return data
def process_file(data):
out_file = input("Enter a name for the output file: ")
output_file= open(out_file, "w")
user_year = int(input("Enter a year: "))
user_int_count= int(input("Enter a integer count: "))
cnt = 0
data.readline()
for line in data:
cnt+= 1
field = line.strip().split()
line_list = [int(n) for n in field]
total = sum(line_list[1:])
year = line_list[0]
avg = int(round((total/12),0))
if user_year == year:
output_file.write("{:<d} {:<d}".format(year, avg))
print()
print( "{:<d} {:<d}".format(year, avg))
output_file.close()
def main():
while True:
try:
f=open_file()
break
except FileNotFoundError:
print("Invalid file name. Try Again.")
process_file(f)
f.close()
main()
【问题讨论】:
-
我认为
for i to range(user_int_count): print(User_year+i)是您要找的? -
您的问题属于邮件正文,而不是标题。