How do i get a function to read a certain amount of lines and then compute a total by adding up the numbers from those lines printing it then looping to read the next lines etc. The function opens up a file that has hundreds of lines with numbers on them.
Example:
def open_input_file():
    while True:
        name_of_file = input("Enter the name of the input file: ")
        try:
            file_wanted = open(name_of_file, 'r')
            return file_wanted
        except FileNotFoundError:
            print(f"The file {name_of_file} was not found. Check the file name and try again.")
def average_steps(read_file, amount_of_days):
    open(read_file.name, 'r')
    amount_of_lines = len(open(read_file.name).readlines(amount_of_days))
    total = 0
    for line in read_file:
        num = int(line)
        total += num
    average = total / amount_of_lines
    return average
def main():
    file_wanted = open_input_file()
    month_list = ['January', 'February', 'March', 'April',
                  'May', 'June', 'July', 'August', 'September',
                  'October', 'November', 'December']
    day_list = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    day_being_used = 0
    month_being_used = 0
    months = 12
    for month_being_used in range(months):
        steps = average_steps(file_wanted, day_list[day_being_used])
        print(f"The average steps taken in {month_list[month_being_used]} was {steps} ")
        day_being_used += 1
        month_being_used += 1
    file_wanted.close()
if __name__ == '__main__':
    main()
 
    