# Arup Guha
# 11/24/2020
# Cereal Finder


# Store each line of the file.
file = open("cereal.csv", "r")
allLines = list(file)

# All the categories of information per cereal.
categories = allLines[0].split(",")

# Get indexes for the things we care about.
categoryMap = {}
for i in range(len(categories)):
    categoryMap[categories[i].rstrip()] = i
calIndex = categoryMap["calories"]
carbIndex = categoryMap["carbo"]
ratingIndex = categoryMap["rating"]

# Store each cereal in order of the file.
allCereals = []
for i in range(1, len(allLines)):
    allCereals.append(allLines[i].split(","))

# Ask for max calorie
maxCal = int(input("What is the max calories for your cereal?\n"))

# Ask for max carbs.
maxCarbs = int(input("What is the max grams of carbs for your cereal?\n"))

# Ask for min rating
minRating = float(input("What is the minimum rating(10,70)?\n"))

print("Here are all the cereals that satisfy your constraints.")

# Go through each cereal
for i in range(len(allCereals)):
    if float(allCereals[i][calIndex]) <= maxCal and float(allCereals[i][carbIndex]) <= maxCarbs and float(allCereals[i][ratingIndex]) >= minRating:
        print(allCereals[i][0])
