Random Generator Not Working

Problem: Instead of randomly choosing one “quote” from the list, it prints ALL of them.

Repl link: https://replit.com/@Wenhan-Benjamin/Draft-Quote-Generator#main.py

Code below:

import time, random

print("Welcome to the Quote Generator!")
print("Enter a name (or 'done' to finish): ")

names = []
name = []

while name != "done":
  name = input()
  names.append(name)
  time.sleep(1)
# Assign names to Person1, Person2, and Person3

Person1 = names[0] if len(names) > 0 else ""
Person2 = names[1] if len(names) > 1 else ""
Person3 = names[2] if len(names) > 2 else ""

# Print Quote

quote1 = [
  print(Person1 + ": *grinning*, Before you were what?"),
  print(Person2 + ": Before I was-"),
  print(Person1 + ": What?"),
  print(Person2 + ": Before I was inter-"),
  print(Person1 + ": Before you were interrupted?"),
  print(Person2 + ": Cut me off one more time and I swear I'll-"),
  print(Person1 + ": *starts to laugh*"),
  print(Person2 + ": *makes frustrated sound*"),
  print(Person3 + ": *nervously*, Stop that. Before they hurt you."),
]

quote2 = {
  print(Person1 + ": Would you slap", Person3 + "-"),
  print(Person2 + ": Yes."),
  print(Person1 + ": I didn't even finish!"),
  print(Person2 + ": Sorry, continue."),
  print(Person1 + ": Would you slap", Person3, "for 10 dollars?"),
  print(Person2 + ": I would do it for free."),
  print(Person3 + ": Rude..."),
}

quote3 = {
  print(Person2 + ": Define “dream”."),
  print(
    Person1
    + ": Dream - the first thing people abandon when they learn how the world"
    " works."
  ),
  print(Person3 + ": That’s too dark!"),
}

quote4 = {
  print(Person2 + ": I asked", Person3, "out."),
  print(Person1 + ": Oh, I’m sorry."),
  print(Person2 + ": Why?"),
  print(Person1 + ": Well, I assume they said no."),
  print(Person2 + ": No, they said yes."),
  print(Person1 + ": Really? Then I’m sorry for them."),
}

quote5 = {
  print(
    Person1 + ":",
    Person3,
    (
      "told me I was found in a KFC bucket next to a dumpster and I was"
      " rescued."
    ),
  ),
  print(Person2 + ": You probably were."),
  print(
    Person1
    + ": Oh crap, maybe that's the reason why. Maybe my lackluster feelings"
    " towards their fried chicken is because subconsciously I'm reliving"
    " the trauma whenever I see their trademark bucket. My brain and"
    " cognitive dissonance won't let me completely lie to myself and say I"
    " hate their food, because fried chicken is great and I want some now,"
    " instead it just steers me away. Thank you for helping to guide me"
    " towards this epiphany, perhaps now the healing can begin."
  ),
}

quote6 = {
  print(Person1 + ":", Person3 + ", I am questioning your sanity..."),
  print(
    Person2
    + ": I never questioned it, I knew their sanity was missing from the"
    " start."
  ),
}

quote7 = {
  print(Person1, ": There's no way they like me back."),
  print(
    Person2 + ":",
    Person3,
    "would throw themself in front of a moving car for you.",
  ),
  print(
    Person1 + ":",
    Person3,
    "would throw themself in front of a moving car for fun.",
  ),
}

quote8 = {
  print(Person3 + ": Dandelions symbolize everything I want to be in life."),
  print(Person1 + ": Fluffy and dead with a gust of wind?"),
  print(
    Person3
    + ": Unapologetic. Hard to kill. Feral, filled with sunlight, bright,"
    " beautiful in a way that the conventional and controlling hate but"
    " cannot ever fully destroy. Stubborn. Happy. Bastardous. Friends with"
    " bees. Highly disapproving of lawns. Full of wishes that will be"
    " carried far after I die."
  ),
  print(Person2 + ": Edible."),
}

quote9 = {
  print("*playing twister*"),
  print(Person2 + ": Right hand red."),
  print(Person3 + ": *ends up on top of Han*"),
  print(Person1 + ": You're doing this on purpose, aren't you?"),
  print(
    Person2
    + ": I stopped spinning like 15 minutes ago. Honestly, I'm surprised you"
    " didn't notice."
  ),
}

quote10 = {
  print(Person2 + ": Who wants to make fifty bucks?"),
  print(Person1 + ": How?"),
  print(Person2 + ": need someone to take the fall."),
  print(Person1 + ": What did you do?"),
  print(Person2 + ": I can't tell you. Yes or no, no questions asked."),
  print(Person3 + ", from the other room: Oh my god."),
  print(Person2 + ": ..."),
  print(Person3 + ": OH MY GOD!"),
  print(Person1 + ": Make it a hundred."),
  print(Person2 + ": Deal."),
}

quote11 = {
  print(Person3 + ": Do you guys want to see a butterfly?"),
  print(Person1 + ": Ooh, yes please!"),
  print(
    Person2,
    (
      "with their laptop open: I'm not going to stop working to look at a"
      " stupid bug!"
    ),
  ),
  print(Person3 + ": It's not a bug though..."),
  print(Person2 + ": ..."),
  print(Person1 + ": ..."),
  print(Person2 + ": Well I still don't want to see."),
  print(Person1 + ", realizing: Please don't throw-"),
  print(Person3 + ": Whee! *throws a stick of butter*"),
}

listOfQuotes = [
  quote1,
  quote2,
  quote3,
  quote4,
  quote5,
  quote6,
  quote7,
  quote8,
  quote9,
  quote10,
  quote11,
]

chosenQuote = random.choice(listOfQuotes)

print("")
print("")
print(chosenQuote)

Hi @Wenhan-Benjamin thanks for your question.

I’m not sure why you are using those sections to define a series of print statements. I’ve not seen that before in Python and it definitely doesn’t do what you want it to do. If you have a link to a resource where you have seen that used for Python let me know and I’ll investigate further.

However, I would choose to use a procedure for each of the quotes. It requires a little change at the end of the program so you aren’t printing the chosen quote, but are calling the procedure instead.

I forked your code and edited it here https://replit.com/@IanAtReplit/Draft-Quote-Generator you are welcome to copy the code back into your own program.

Hope it helps.

2 Likes

Yes, you could have used mine (very long) or @IanAtCSTeach 's one (sooo much faster).