Home > Back-end >  My break statements aren't being reached and I don't know what questions to ask
My break statements aren't being reached and I don't know what questions to ask

Time:09-03

Ok so I am super new, I feel like I don't even know what I'm doing half the time so I have no idea what is wrong here or how to fix it- I added a choice option to pick the function containing separate little stories, but it will only ever run the first one, so I tried a break but it can't be reached so- I'm lost. (Also I know some of this stuff is cheeky just play along haha)

import time

print("\nHello human with reading and writing ability, please choose a passage from the choices below:\n\n1.Party Decisions\n2.Dating Advice\n3.Human Interaction\n4.Fish\n5.Pirates\n\n")
choice = int(input("Choose the number of the passage you want to use and press enter: "))
print()


def choose():
    while int(choice):
        if choice == 1:
            return madlib1()
            break
        if choice == 2:
            return madlib2()
            break
        if choice == 3:
            return madlib3()
            break
    """ if choice == 4:
            return madlib4()
            
        else:
            return madlib5()
             """


def madlib1():
    type_of_liquid = input("Enter a type of liquid: ")
    adjective1 = input("Enter an adjective: ")
    number = input("Enter a number: ")
    adjective2 = input("Enter the second adjective: ")
    noun1 = input("Enter a noun: ")
    adjective3 = input("Enter the third adjective: ")
    adjective4 = input("Enter the fourth adjective: ")
    type_of_food = input("Enter a type of food: ")
    adjective5 = input("God, enter another adjective: ")
    adjective6 = input("ANOTHER ONE?? Adjective pls: ")
    body_part = input("Enter a body part (wink-wonk ;-)): ")
    noun2 = input("Enter another noun: ")
    adjective7 = input("OK last one I swear, adjective: ")
    verb1 = input("Enter a verb: ")
    plural_noun = input("Enter a plural noun: ")
    place = input("Enter a place: ")
    print("OK one more thing.")
    verb2 = input("Enter one last verb: ")

    print("Calculating.......")
    time.sleep(5)

    print("When you show up for a rooftop party, the "   type_of_liquid   " you choose to drink is very important. After all the weather is usually "   adjective1   ", the party lasts for "   number   " hours, and you don't want to get "   adjective2   " too early. So what should you drink? You take a look in the cooler, and the first "   noun1   " you come across is a stout. You usually love to drink such a dark, "   adjective3   " beer, but it might be a little too "   adjective4   " for this occasion. You don't want to feel like you just ate a loaf of "   type_of_food   ". What about a wheat beer? It seems like the most "   adjective5   " choice for a summer party. You love the "   adjective6   " taste, but it also gives you a raging "   body_part   "-ache. In the end you choose a/an "   noun2   " Light, your usual go-to. It's "   adjective7   ", easy to "   verb1   ", and goes with all the "   plural_noun   " you plan to eat. Only problem is you might have to make more trips to (the) "   place   " than usual- "   noun2   " Light makes you "   verb2   " all night long.")


madlib1()


def madlib2():
    noun1 = input("Noun pls: ")
    place = input("A place: ")
    adjective1 = input("Now an adjective: ")
    noun2 = input("Another noun pls sir: ")
    noun3 = input("Oops another (noun): ")
    animal = input("Now let's do an animal: ")
    ing_verb = input("Give me a verb ending in -ing: ")
    plural_noun = input("A plural noun: ")
    plural_noun2 = input("Another one: ")
    adjective2 = input("Adjective: ")
    verb = input("Gimme a verb: ")
    plural_noun3 = input("Jesus another plural noun: ")
    plural_noun4 = input("Spoke too soon, another: ")
    noun4 = input("NOUN!!: ")
    ing_verb2 = input("Another -ing verb pls: ")
    noun5 = input("Another noun sir: ")
    type_of_liquid = input("Liquid?: ")
    plural_noun5 = input("One more plural noun I promise: ")
    clothing = input("Give an article of clothing: ")
    adjective3 = input("One last adjective!!: ")
    print()

    print("Calculating.......\n\n")
    time.sleep(5)


    print("Where can you meet a nice, normal "   noun1   " to date?\nSure, there are traditional avenues like the workplace or (the) "   place   ", but here are some other creative, "  adjective1   " ways:\n*Show off your sexy athletic skills by joining a/an "  noun2   "-ball team at a rec center.\n*Walk your favourite four-legged "   noun3   " at the local "   animal   " park.\n*Attend a/an "   ing_verb   " class at a community college.\n*Look for antique "   plural_noun   " for your collection at a flea market.\n*Suggestively squeeze the largest, juicest "  plural_noun2   " while exploring the "   adjective2   " farmers' market.\n*"   verb   " with hundreds of other crazy " plural_noun3   " as part of a flash mob.\n*Volunteer to plant "   plural_noun4   " at a neighborhood park.\n*Try daring, "   noun4   "-defying new adventures like sky-"   ing_verb2   ".\n*Go to cultural events like "   noun5   " museums or "   type_of_liquid   " tastings.\n*Do cardio or lift "   plural_noun5   " at the gym in your tightest "   clothing   "-you'll feel fit and look "   adjective3   "!")

madlib2()

def madlib3():
    foreign_country = input("Enter a foreign country: ")
    adverb = input("Gimme an adverb (ex. quickly): ")
    adjective = input("An adjective now: ")
    animal = input("How bout an animal: ")
    ing_verb = input("A verb ending in -ing: ")
    verb = input("Just a plain 'ol verb: ")
    ing_verb2 = input("Now another -ing verb: ")
    adverb2 = input("'nother adverb pls: ")
    adjective2 = input("A nice new adjective here: ")
    place = input("Name a place: ")
    liquid = input("Now a type of liquid: ")
    body_part = input("I want a body part now: ")
    verb2 = input("Lastly, a final verb: ")

    print("Calculating.......\n\n")
    time.sleep(5)

    print("If you are traveling in "   foreign_country   "and find yourself having to cross a piranha-filled river, here's how to do it "   adverb   ":\n*Piranhas are more "   adjective   " during the day, so cross the river ata night.\n*Avoid areas with netted "   animal   " traps- piranhas may be "   ing_verb   " there looking to "   verb   " them!\n*When "   ing_verb2   " the river, swim "   adverb2   ". You don't want to wake them up and make them "   adjective2   "!\n*Whatever you do, if you have an open wound, try to find another way to get back to the "   place   ". Piranhas are attracted to fresh "   liquid   " and will most likely take a bite out of your "   body_part   " if you "   verb2   " in the water!")

madlib3()

CodePudding user response:

OK first off, the code isn't all good but I won't talk about that, I will only answer your question.

Don't call the functions if you are intending to let the user to choose.

So this means to delete

madlib1()
madlib2()
madlib3()

Under each function

Next :

In this function :

def choose():
while int(choice):
    if choice == 1:
        return madlib1()
        break
    if choice == 2:
        return madlib2()
        break
    if choice == 3:
        return madlib3()
        break

Some things are not right, first you don't really need a while function, second you don't need to put int(choice), And if you do need it, it should be passed on as an argument for the function. And you don't return a function, you call it. Also after the first if statement the other ones turn into elif or else statements. And finally put the function at the end of the file and call choose function after it.

It should look like this :

----
def choose(choice):
    if choice == 1:
        madlib1()
    elif choice == 2:
        madlib2()
    elif choice == 3:
        madlib3()
choose(choice)

Now that we got rid of the while function you don't need the break.

CodePudding user response:

import time

print(
    "\nHello human with reading and writing ability, please choose a passage from the choices below:\n\n1.Party Decisions\n2.Dating Advice\n3.Human Interaction\n4.Fish\n5.Pirates\n\n")
choice = int(input("Choose the number of the passage you want to use and press enter: "))
print()


def choose(choice):
    while int(choice):
        if choice == 1:
            madlib1()
            return
        if choice == 2:
            madlib2()
            return
        if choice == 3:
            return madlib3()
            return
    """ if choice == 4:
            return madlib4()

        else:
            return madlib5()
             """

def madlib1():
    type_of_liquid = input("Enter a type of liquid: ")
    adjective1 = input("Enter an adjective: ")
    number = input("Enter a number: ")
    adjective2 = input("Enter the second adjective: ")
    noun1 = input("Enter a noun: ")
    adjective3 = input("Enter the third adjective: ")
    adjective4 = input("Enter the fourth adjective: ")
    type_of_food = input("Enter a type of food: ")
    adjective5 = input("God, enter another adjective: ")
    adjective6 = input("ANOTHER ONE?? Adjective pls: ")
    body_part = input("Enter a body part (wink-wonk ;-)): ")
    noun2 = input("Enter another noun: ")
    adjective7 = input("OK last one I swear, adjective: ")
    verb1 = input("Enter a verb: ")
    plural_noun = input("Enter a plural noun: ")
    place = input("Enter a place: ")
    print("OK one more thing.")
    verb2 = input("Enter one last verb: ")

    print("Calculating.......")
    time.sleep(5)

    print(
        "When you show up for a rooftop party, the "   type_of_liquid   " you choose to drink is very important. After all the weather is usually "   adjective1   ", the party lasts for "   number   " hours, and you don't want to get "   adjective2   " too early. So what should you drink? You take a look in the cooler, and the first "   noun1   " you come across is a stout. You usually love to drink such a dark, "   adjective3   " beer, but it might be a little too "   adjective4   " for this occasion. You don't want to feel like you just ate a loaf of "   type_of_food   ". What about a wheat beer? It seems like the most "   adjective5   " choice for a summer party. You love the "   adjective6   " taste, but it also gives you a raging "   body_part   "-ache. In the end you choose a/an "   noun2   " Light, your usual go-to. It's "   adjective7   ", easy to "   verb1   ", and goes with all the "   plural_noun   " you plan to eat. Only problem is you might have to make more trips to (the) "   place   " than usual- "   noun2   " Light makes you "   verb2   " all night long.")

def madlib2():
    noun1 = input("Noun pls: ")
    place = input("A place: ")
    adjective1 = input("Now an adjective: ")
    noun2 = input("Another noun pls sir: ")
    noun3 = input("Oops another (noun): ")
    animal = input("Now let's do an animal: ")
    ing_verb = input("Give me a verb ending in -ing: ")
    plural_noun = input("A plural noun: ")
    plural_noun2 = input("Another one: ")
    adjective2 = input("Adjective: ")
    verb = input("Gimme a verb: ")
    plural_noun3 = input("Jesus another plural noun: ")
    plural_noun4 = input("Spoke too soon, another: ")
    noun4 = input("NOUN!!: ")
    ing_verb2 = input("Another -ing verb pls: ")
    noun5 = input("Another noun sir: ")
    type_of_liquid = input("Liquid?: ")
    plural_noun5 = input("One more plural noun I promise: ")
    clothing = input("Give an article of clothing: ")
    adjective3 = input("One last adjective!!: ")
    print()

    print("Calculating.......\n\n")
    time.sleep(5)

    print(
        "Where can you meet a nice, normal "   noun1   " to date?\nSure, there are traditional avenues like the workplace or (the) "   place   ", but here are some other creative, "   adjective1   " ways:\n*Show off your sexy athletic skills by joining a/an "   noun2   "-ball team at a rec center.\n*Walk your favourite four-legged "   noun3   " at the local "   animal   " park.\n*Attend a/an "   ing_verb   " class at a community college.\n*Look for antique "   plural_noun   " for your collection at a flea market.\n*Suggestively squeeze the largest, juicest "   plural_noun2   " while exploring the "   adjective2   " farmers' market.\n*"   verb   " with hundreds of other crazy "   plural_noun3   " as part of a flash mob.\n*Volunteer to plant "   plural_noun4   " at a neighborhood park.\n*Try daring, "   noun4   "-defying new adventures like sky-"   ing_verb2   ".\n*Go to cultural events like "   noun5   " museums or "   type_of_liquid   " tastings.\n*Do cardio or lift "   plural_noun5   " at the gym in your tightest "   clothing   "-you'll feel fit and look "   adjective3   "!")

def madlib3():
    foreign_country = input("Enter a foreign country: ")
    adverb = input("Gimme an adverb (ex. quickly): ")
    adjective = input("An adjective now: ")
    animal = input("How bout an animal: ")
    ing_verb = input("A verb ending in -ing: ")
    verb = input("Just a plain 'ol verb: ")
    ing_verb2 = input("Now another -ing verb: ")
    adverb2 = input("'nother adverb pls: ")
    adjective2 = input("A nice new adjective here: ")
    place = input("Name a place: ")
    liquid = input("Now a type of liquid: ")
    body_part = input("I want a body part now: ")
    verb2 = input("Lastly, a final verb: ")

    print("Calculating.......\n\n")
    time.sleep(5)

    print(
        "If you are traveling in "   foreign_country   "and find yourself having to cross a piranha-filled river, here's how to do it "   adverb   ":\n*Piranhas are more "   adjective   " during the day, so cross the river ata night.\n*Avoid areas with netted "   animal   " traps- piranhas may be "   ing_verb   " there looking to "   verb   " them!\n*When "   ing_verb2   " the river, swim "   adverb2   ". You don't want to wake them up and make them "   adjective2   "!\n*Whatever you do, if you have an open wound, try to find another way to get back to the "   place   ". Piranhas are attracted to fresh "   liquid   " and will most likely take a bite out of your "   body_part   " if you "   verb2   " in the water!")

choose(choice)

you simply haven't ran the function choose.

Run the function choose and give it the input choice as its argument.

  • Related