![]() |
code won't advance to next statement - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: code won't advance to next statement (/thread-39767.html) |
code won't advance to next statement - MCL169 - Apr-11-2023 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)) 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.
RE: code won't advance to next statement - deanhystad - Apr-11-2023 Don't you want to exit the loop when the input is good? Do you know what continue does? RE: code won't advance to next statement - Larz60+ - Apr-11-2023 MCL169 -- Please do not double post. |