I want to read a csv file, ask the user for what column they would like to search, then output summary data for that column. This is what I've done so far:
import csv
data = open('data.csv')
reader = csv.reader(data, delimiter = ',')
category = input("What category would you like to look up? Please enter 'city', or 'state': ")
category = category.upper()
if category == "city":
city = input("Enter a city: ")
city = city.upper()
if row[3] == city:
print(row)
else:
print("That is not a city.")
elif category == "state":
state = input("Enter a state: ")
state = state.upper()
if row[1] == state:
print(row)
else:
print("That is not a state.")
However, no matter what I input after selecting a category, I keep getting the error of this is not a city/state. Where am I going wrong?
Aucun commentaire:
Enregistrer un commentaire