Lists and user input

I’m creating a book recommendation program and I want to figure out an easier way to check if the age that the user inputs matches up with any of the age groups that are arranged in lists (kids, teens, and adults). Someone please help!!

Please provide some code you already have. That makes it easier to help

2 Likes

image

You can check if the age is in your list. Another trick is to use the .lower() method so you don’t need to check for different capitalization like so:

genre = genre.lower()
elif genre == "fantasy":
  if age in youthAges:
     print("\nHere are your recommendations:"
     print(fantasyPG)
1 Like

Hi,there!

Also, in order to get the input age and avoid misspelling, yo can another trick:

genre = genre.lower()```

elif genre[0] == "f":
  if age in youthAges:
     print("\nHere are your recommendations:")
     print(fantasyPG)
2 Likes