Sep-29-2018, 03:15 AM
My code works just fine but when I introduced the 2nd if statement that returns
this is my code
Output:City not found!
then thats the only thing my code will return regardless if the city is in the text filethis is my code
# Week 5 Lab # Exercise 1 city = input('Enter a city ') # asks for user input with open('cities.txt','r', encoding = 'cp1252') as f: # opens a file and encodes for errors for line in f: if city in line: l1 = line[0:2] # assigns a variable to certain range of characters t1 = line[3:5] c1 = line[5] l2 = line[7:9] t2 = line[10:12] c2 = line[12] print(city, 'is',l1, 'degrees',t1,'minutes',c1, 'and', l2, 'degrees',t2, 'minutes', c2) # prints coordinates if city not in line: print('City not found!') break f.close() # closes the filehow can I fix this? I know the issue is in the way I introduced the second if statement