Apr-11-2023, 07:53 PM
(This post was last modified: Apr-11-2023, 08:23 PM by deanhystad.)
while True: # bool, True year = input('please enter a 4-digit year: ') digit = len(year) # int, 4 if digit != 4 or not year.isdigit(): # bool, False print("sorry, that was bad input") else: continue lines = open('FF_data.txt') sum = 0.0 # float, 0.0 count = 0 # int, 0 for line in lines: curr_line = line.split() my_date = curr_line[0] # str, list if year == my_date[0:4]: sum = sum + float(curr_line[1]) count = count + 1 lines = open('FF_data.txt') # list, str sum = 0.0 # float, 0.0 count = 0 # int, 0 for line in lines: curr_line = line.split() # list, str my_date = curr_line[0] # str, list if year == my_date[0:4]: sum = sum + float(curr_line[1]) # float, float count = count + 1 # int, int avg = sum / count print('count',count,',sum',round(sum, 2,), 'avg',round(avg, 2))
Output:please enter a 4-digit year: 1990
please enter a 4-digit year:
My code was working but the professor doesnt want me to nest one part inside another. When I stepped outside the loop the program stopped advancing.