New to coding and pranking friend who knows nothing, but my script input breaks

Question:

I know it sounds dumb, but I am making an annoying baby simulation that repeatedly asks questions unless given an exact input response to prank a friend.

I have a set of random questions as well as random follow-up questions to feed to him while he will toil away until he essentially discovers the "password" input. My follow-up questions, however, will not randomize and instead select only one out of the list and then break the code entirely, making the new input prompt a random character/element over and over again infinitely.

I have tried placing another while loop within the while loop to assert more definite randomness to the follow-up question pulling and hopefully fix the input prompt issue, but I am not even sure if you can do such a thing successfully and it didn’t work so I removed it, and I am still REALLY new to coding entirely.

I may just be over my head despite the idea seeming relatively simple so the solution may be something I haven’t learned, but here is my silly prank script that I cant fix:


from random import choice

new_questions = ["Where are all the dinosaurs?: ", "How are babies made?: ", "Why don't we have superpowers?: ", "Why is the sky blue?: "]
questions = ["Well why is the sky blue then?!: ", "Why though?: ", "I still don't get it...why?: ", "OHH OKAY...no, no, wait, but...Why?: ", "WHY?!: ", "You suck at explaining things...just tell me why already.: ", "Why?: ", "What does that have to do with the sky being blue...?: ", "Yeah, I get that part, but why?: ", "Ok, why?: "]

new_questions = choice(new_questions)
answer = input(new_questions).strip().lower()

while answer != "just because":
    questions = choice(questions)
    answer = input(questions).strip().lower()

I have yet to finish it, as I am still trying to understand why this first part breaks.

Upon running, you will see that it executes most of it well, but it cannot randomly pick from my variable "questions" multiple times randomly, and it also breaks after the first pull from the questions list and will consequently only ask for an input with a singular character element instead.

Asked By: Journee

||

Answers:

You’re overwriting the question list in questions = choice(questions) by assign it a new value (the choice). Change it to:

while answer != "just because":
    question = choice(questions)
    answer = input(question).strip().lower()

Answered By: Matheus Delazeri

You don’t want to do questions = choice(questions) because that replaces the list of questions with a single randomly chosen questions. Instead, something like

while answer != "just because":
    question = choice(questions)
    answer = input(question).strip().lower()

Notice that questions is now left undisturbed.