Function help pls!

image

I’m trying to create a program that gives book recommendations based on a users preference and age. I made a function to correctly choose the genre and age appropriate books that are all inside lists. The procedure is essentially the same for each genre. I also have lists for the different age ranges. However when I run the program, it will ask the user the questions but will not output anything. I’m wondering what I need to fix please help!!

You cannot write if A==“something” or “Something”
You need to write

if a==“something” or a==“Something”

Or

if a.lower()==“something”

3 Likes

I don’t know where you got this from but that’s not true.

I mean, it will always return true, but it is probably not what the author intended.

2 Likes

The author’s code looks fine except for the excessive spaces between code which could be his error.

it is ambiguous as he means a==“” or a == “”, while he is writing (a==“”) or “” that indeed is always true.

2 Likes

i think we need to see the rest of the code …

2 Likes

Here is his code:

import random
import time
import sys


romanceTeen = ["All The Bright Places by Jennifer Nieven", "Everything Everything by Nicola Yoon", "Better Than the Movies by Lynn Painter", "The upside of falling by Alex Light", "Today Tonight Tomrrow by Rachel Solomon"]
pricesRT = ["ATBP - Amazon: $7.48, Barnes and noble: $9.99", "EE - Amazon: $8.49, Barnes and noble: $11.99", "BTTM - Amazon: $13.84, Barnes and noble: $11.49", "TUOF - Amazon: $10.79, Barnes and noble: 14.99", "TTT - Amazon: $10.38, Barnes and noble: $10.99"]

romanceAdult = ["Beach Read by Emily Henry", "Twisted Love by Ana Huang", "The Love Hypothesis by Ali Hazelwood", "The Hating Game by Sally Thorne", "The Unhoneymooners by Christina Lauren", ]
pricesRA= ["BR - Amazon: $7.35, Barnes and noble: $13.99", "TL - Amazon: $10.59, Barnes and noble: $14.99", "TLH - Amazon: $10.70, Barnes and noble: $10.99", "THG - Amazon: $8.70, Barnes and noble: $12.99", "TU - Amazon: 8.87, Barnes and noble: $13.99"]

fantasyPG = ["A Wrinkle in Time by Madeleine L'Engle", "Harry Potter and The Sorcerers Stone", "Miss Peregrines Home for Peculiar Children by Ransom Siggs", "Tuck Everlasting by Natalie Babbit", "The BFG by Roald Dahl", "The Girl Who Drank the Moon by Kelly Barnhill" ]
FpricesPG = ["AWIT - Amazon$8.49, Barnes and noble: $19.49", "HPATSS - Amazon: $6.98, Barnes and noble: $12.99", "MPHFPC - Amazon: $8.89, Barnes and noble: $9.99", "TE - Amazon: $8.81, Barnes and noble: 8.99", "TBFG - Amazon: $8.99, Barnes and noble: $8.99", "TGWDTM - Amazon: $10.66, Barnes and noble: $8.95"]

fantasyTeen = ["The Cruel Prince by Holly Black", "Red Queen by Victoria Aveyard", "Six of Crows by Leigh Bardugo", "Legendborn by Tracy Deonn", "The Hazelwood by Melissa Albert", "An Ember in the ashes by Sabba Tahir"]
pricesFT = ["TCP - Amzazon: $13.54, Barnes and noble: $10.99", "RQ - Amazon: $6.98, Barnes and noble: $10.99", "SOC - Amazon: $16.69, Barnes and noble: $11.49", "LB - Amazon: $11.89, B&N: $11.89", "TH - Amazon: $8.01, B&N: $9.99", "AEITA - Amazon: $8.38, B&N: $11.99"]

fantasyAdult = ["Violet Made of Thorns by Gina Chen", "Cerce by Madeline Miller", "The Poppy War R. F. Kuang", "Graceling by Kristin Cashore", "Prince of Thorns by Mark Lawrence", "The Priory of The Orange Tree by Samantha Shannon"]

horrorPG = ["The Witches by Roald Dahl", "Small Spaces by Katherine Arden", "City of Ghosts by V.E Schwab", "Spirit Hunters by Ellen Oh", "Doll Bones by Holly Black", "The Night Gardener by Jonathan Auxier"]

horrorTeen = ["The Cheerleader by Kara Thomas", "House of Salt of Salt and Sorrows by Erin A. Craig", "A Wicked Magic by Sasha Laurens", "Harrow Lake by Kate Ellis", "The Haunted by Danielle Vega", "A monster calls by Patrick Ness"] 

horrorAdult = ["The Shining by Stephen King", "The Ruins by Scott Smith", "Bird Box by Josh Malerman", "The Hunger by Alma Katsu", "Heart Shaped Box by Joe Hill", "Manhunt by Gretchen Martin"]

classicsPG = ["Charlotte's Web by E.B White", "Charlie and the Chocolate Factory by Roald Dahl", "The Giving Tree by Shel Silverstein", "The Wind in The Willows by Kenneh Grahame", "The Secret Garden by Frances Burnett", "The Tale of Peter Rabbit by Beatrix Potter"] 

classicsTeen = ["Little Women by Louisa Alcott", "The Catcher in the Rye by J. D Sallinger", "The Outsiders by S. E Hinton", "To Kil a Mockingbird by Harper Lee", "The Call of the Wind by Jack London", "The Great Gatspy by F. Fitzgerald"]

classicsAdult = ["Pride and Prejudice by Jane Austen", "The Picture of Dorian Gray by Oscar Wilde", "Fahrenheit 451 by Ray Bradbury", "The Bell Jar by Sylvia Plath", "The Stranger Albert Camus", "Wuthering Heights Emily Brontë"]


#checks the users age and the genre they chose 
#credit and inspiration to movie suggestion program
def bookrecom (genre, age):
  if age <=13:
    if genre == "romance":
      print("Sorry you're too young for this genre! Please pick another.")
    elif genre == "fantasy":
      print("\nHere are your recommendations:\n")
      print(*fantasyPG, sep='\n')
        
    elif genre == "horror":
      print("\nHere are your recommendations:\n")
      print(*horrorPG, sep='\n')
    elif genre == "classics":
      print("\nHere are your recommendations:\n")
      print(*classicsPG, sep='\n')

  elif age >=14 and age <=17:
    if genre == "romance":
      print("\nHere are your recommendations:\n")
      print(*romanceTeen, sep='\n')
    elif genre == "fantasy":
      print("\nHere are your recommendations:\n")
      print(*fantasyTeen, sep='\n')
    elif genre == "horror":
      print("\nHere are your recommendations:\n")
      print(*horrorTeen, sep='\n')
    elif genre == "classics":
      print("\nHere are your recommendations:\n")
      print(*classicsTeen, sep='\n')

  elif age >= 18:
    if genre == "romance":
      print("\nHere are your recommendations:\n")
      print(*romanceAdult, sep='\n')
    elif genre == "fantasy":
      print("\nHere are your recommendations:\n")
      print(*fantasyAdult, sep='\n')
    elif genre == "horror":
      print("\nHere are your recommendations:\n")
      print(*horrorAdult, sep='\n')
    elif genre == "classics":
      print("\nHere are your recommendations:\n")
      print(*classicsAdult, sep='\n')
  
      
genre = str(input("Please select the book genre you like the most: \n\nRomance (only choose if you are 14 or older)        \nFantasy    \nHorror       \nClassics \n"))
age = int(input("Please enter your age: "))
if genre == "romance" or genre == "Romance":
  bookrecom (genre, age)
elif genre == "fantasy" or genre == "Fantasy":
  bookrecom (genre, age) 
elif genre == "Horror" or genre == "horror":
    bookrecom (genre, age) 
else:
  bookrecom (genre, age) 
x = 0
cost = str(input("\nWould you like to know what each book costs and \nwhere you can find them?: "))
if cost == "yes":
  x = int(input("\nPlease indicate how many books you would like to know the price of. if you would like to know all of them please type all, if you would like to know all of them, please type 'all': "))
  if age <=14:
    if genre == "romance":
      print("\nEach book is represented by acronyms of the titles.\n")
      print(*pricesRT, sep='\n')

    elif genre == "fantasy":
      print("\nEach book is represented by acronyms of the titles.\n")
      print(*FpricesPG, sep='\n')

Now here is his code formatted:

import random
import time
import sys


romanceTeen = [
    "All The Bright Places by Jennifer Nieven",
    "Everything Everything by Nicola Yoon",
    "Better Than the Movies by Lynn Painter",
    "The upside of falling by Alex Light",
    "Today Tonight Tomrrow by Rachel Solomon",
]
pricesRT = [
    "ATBP - Amazon: $7.48, Barnes and noble: $9.99",
    "EE - Amazon: $8.49, Barnes and noble: $11.99",
    "BTTM - Amazon: $13.84, Barnes and noble: $11.49",
    "TUOF - Amazon: $10.79, Barnes and noble: 14.99",
    "TTT - Amazon: $10.38, Barnes and noble: $10.99",
]

romanceAdult = [
    "Beach Read by Emily Henry",
    "Twisted Love by Ana Huang",
    "The Love Hypothesis by Ali Hazelwood",
    "The Hating Game by Sally Thorne",
    "The Unhoneymooners by Christina Lauren",
]
pricesRA = [
    "BR - Amazon: $7.35, Barnes and noble: $13.99",
    "TL - Amazon: $10.59, Barnes and noble: $14.99",
    "TLH - Amazon: $10.70, Barnes and noble: $10.99",
    "THG - Amazon: $8.70, Barnes and noble: $12.99",
    "TU - Amazon: 8.87, Barnes and noble: $13.99",
]

fantasyPG = [
    "A Wrinkle in Time by Madeleine L'Engle",
    "Harry Potter and The Sorcerers Stone",
    "Miss Peregrines Home for Peculiar Children by Ransom Siggs",
    "Tuck Everlasting by Natalie Babbit",
    "The BFG by Roald Dahl",
    "The Girl Who Drank the Moon by Kelly Barnhill",
]
FpricesPG = [
    "AWIT - Amazon$8.49, Barnes and noble: $19.49",
    "HPATSS - Amazon: $6.98, Barnes and noble: $12.99",
    "MPHFPC - Amazon: $8.89, Barnes and noble: $9.99",
    "TE - Amazon: $8.81, Barnes and noble: 8.99",
    "TBFG - Amazon: $8.99, Barnes and noble: $8.99",
    "TGWDTM - Amazon: $10.66, Barnes and noble: $8.95",
]

fantasyTeen = [
    "The Cruel Prince by Holly Black",
    "Red Queen by Victoria Aveyard",
    "Six of Crows by Leigh Bardugo",
    "Legendborn by Tracy Deonn",
    "The Hazelwood by Melissa Albert",
    "An Ember in the ashes by Sabba Tahir",
]
pricesFT = [
    "TCP - Amzazon: $13.54, Barnes and noble: $10.99",
    "RQ - Amazon: $6.98, Barnes and noble: $10.99",
    "SOC - Amazon: $16.69, Barnes and noble: $11.49",
    "LB - Amazon: $11.89, B&N: $11.89",
    "TH - Amazon: $8.01, B&N: $9.99",
    "AEITA - Amazon: $8.38, B&N: $11.99",
]

fantasyAdult = [
    "Violet Made of Thorns by Gina Chen",
    "Cerce by Madeline Miller",
    "The Poppy War R. F. Kuang",
    "Graceling by Kristin Cashore",
    "Prince of Thorns by Mark Lawrence",
    "The Priory of The Orange Tree by Samantha Shannon",
]

horrorPG = [
    "The Witches by Roald Dahl",
    "Small Spaces by Katherine Arden",
    "City of Ghosts by V.E Schwab",
    "Spirit Hunters by Ellen Oh",
    "Doll Bones by Holly Black",
    "The Night Gardener by Jonathan Auxier",
]

horrorTeen = [
    "The Cheerleader by Kara Thomas",
    "House of Salt of Salt and Sorrows by Erin A. Craig",
    "A Wicked Magic by Sasha Laurens",
    "Harrow Lake by Kate Ellis",
    "The Haunted by Danielle Vega",
    "A monster calls by Patrick Ness",
]

horrorAdult = [
    "The Shining by Stephen King",
    "The Ruins by Scott Smith",
    "Bird Box by Josh Malerman",
    "The Hunger by Alma Katsu",
    "Heart Shaped Box by Joe Hill",
    "Manhunt by Gretchen Martin",
]

classicsPG = [
    "Charlotte's Web by E.B White",
    "Charlie and the Chocolate Factory by Roald Dahl",
    "The Giving Tree by Shel Silverstein",
    "The Wind in The Willows by Kenneh Grahame",
    "The Secret Garden by Frances Burnett",
    "The Tale of Peter Rabbit by Beatrix Potter",
]

classicsTeen = [
    "Little Women by Louisa Alcott",
    "The Catcher in the Rye by J. D Sallinger",
    "The Outsiders by S. E Hinton",
    "To Kil a Mockingbird by Harper Lee",
    "The Call of the Wind by Jack London",
    "The Great Gatspy by F. Fitzgerald",
]

classicsAdult = [
    "Pride and Prejudice by Jane Austen",
    "The Picture of Dorian Gray by Oscar Wilde",
    "Fahrenheit 451 by Ray Bradbury",
    "The Bell Jar by Sylvia Plath",
    "The Stranger Albert Camus",
    "Wuthering Heights Emily Brontë",
]


# checks the users age and the genre they chose
# credit and inspiration to movie suggestion program
def bookrecom(genre, age):
    if age <= 13:
        if genre == "romance":
            print("Sorry you're too young for this genre! Please pick another.")
        elif genre == "fantasy":
            print("\nHere are your recommendations:\n")
            print(*fantasyPG, sep="\n")

        elif genre == "horror":
            print("\nHere are your recommendations:\n")
            print(*horrorPG, sep="\n")
        elif genre == "classics":
            print("\nHere are your recommendations:\n")
            print(*classicsPG, sep="\n")

    elif age >= 14 and age <= 17:
        if genre == "romance":
            print("\nHere are your recommendations:\n")
            print(*romanceTeen, sep="\n")
        elif genre == "fantasy":
            print("\nHere are your recommendations:\n")
            print(*fantasyTeen, sep="\n")
        elif genre == "horror":
            print("\nHere are your recommendations:\n")
            print(*horrorTeen, sep="\n")
        elif genre == "classics":
            print("\nHere are your recommendations:\n")
            print(*classicsTeen, sep="\n")

    elif age >= 18:
        if genre == "romance":
            print("\nHere are your recommendations:\n")
            print(*romanceAdult, sep="\n")
        elif genre == "fantasy":
            print("\nHere are your recommendations:\n")
            print(*fantasyAdult, sep="\n")
        elif genre == "horror":
            print("\nHere are your recommendations:\n")
            print(*horrorAdult, sep="\n")
        elif genre == "classics":
            print("\nHere are your recommendations:\n")
            print(*classicsAdult, sep="\n")


genre = str(
    input(
        "Please select the book genre you like the most: \n\nRomance (only choose if you are 14 or older)        \nFantasy    \nHorror       \nClassics \n"
    )
)
age = int(input("Please enter your age: "))
if genre == "romance" or genre == "Romance":
    bookrecom(genre, age)
elif genre == "fantasy" or genre == "Fantasy":
    bookrecom(genre, age)
elif genre == "Horror" or genre == "horror":
    bookrecom(genre, age)
else:
    bookrecom(genre, age)
x = 0
cost = str(
    input(
        "\nWould you like to know what each book costs and \nwhere you can find them?: "
    )
)
if cost == "yes":
    x = int(
        input(
            "\nPlease indicate how many books you would like to know the price of. if you would like to know all of them please type all, if you would like to know all of them, please type 'all': "
        )
    )
    if age <= 14:
        if genre == "romance":
            print("\nEach book is represented by acronyms of the titles.\n")
            print(*pricesRT, sep="\n")

        elif genre == "fantasy":
            print("\nEach book is represented by acronyms of the titles.\n")
            print(*FpricesPG, sep="\n")

Firat thing is that you should stick to either capitalised or lowcase as right nit capitalises genre will not work in bookrecom,