Python Forum

Full Version: code won't advance to next statement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Don't you want to exit the loop when the input is good? Do you know what continue does?
MCL169 -- Please do not double post.