Oct-04-2018, 07:51 PM
im creating a program that will tell me what the climate is in a city in the summer and in the winter based on it's latitude. I'm doing this by adding them to separate lists first. How can I have my program skip the first line because it is the header.
my code
my code
with open('cities.txt','r', encoding = 'cp1252') as f: season = input('Will you take your holiday in the summer or winter? ') temp = input('Do you want to go to a destination that is warm or cold? ') summercold = [] summerwarm = [] winterwarm = [] wintercold = [] for line in f: lat = int(line[0:2]) if lat > 66: summercold.append(line) wintercold.append(line) elif lat > 35 and lat < 66: if line[5] == N: summerwarm.append(line) wintercold.append(line) elif line[5] == S: summercold.append(line) winterwarm.append(line) else: summerwarm.append(line) winterwarm.append(line)
Error: lat = int(line[0:2])
ValueError: invalid literal for int() with base 10: 'La'
I'm getting an error because the first line is a string so line[0:2] can't convert it into an integer. How can I skip the first line?