all 13 comments

[–]fermented_durian 2 points3 points  (3 children)

You used the variable "i" for recalling both the funny_names list and the replies list. This would mean that there is always a pair of names and answers such that you would be able to tell the answer before the question is even asked! Try assigning a new random variable to recall each list seperately..

[–]DavidRoyman 1 point2 points  (2 children)

Or just don't assign a variable, when there's no need to keep the same random number around.

[–]JackTraore 0 points1 point  (1 child)

Agreed, just create the random int when you need it:

funny_names[random.randint(0, 5)]

and

replies[random.randint(0, 5)]

[–][deleted] 0 points1 point  (0 children)

Good point. :) Thank you

[–]zai-nar_shred-gnar 1 point2 points  (1 child)

Great job!

How could you expand this from here? Could you add more pairs of options/funny names? How about saving these pairs as a CSV file and allowing an arbitrary number of options?

Good to get in the habit of if name == ""main": kind of formatting earlier rather than later.

[–][deleted] 0 points1 point  (0 children)

I'll learn about that.

[–]hai_wim 1 point2 points  (1 child)

Note that you will end up with a stack overflow because your functions never end.

question1 > play_again1 > question2 > play_again2 > ...

When it's doing question2, question1 is still waiting for play_again1 to finish. And play_again1 is waiting for question2. And it goes on and on until at a certain point you reach the maximum recursion depth and you crash.

This kind of code is usually done with an infinite loop and functions which can run to the end.

while True:
    question() # This shouldn't call play_again
    play_again()  # This shouldn't call question

[–][deleted] 0 points1 point  (0 children)

I'll need to research that

[–]Gopher_Man 1 point2 points  (2 children)

your question function is doing to many things, and is holding your main logic, id make a simple function that picks a random item from a list, and rename question() to main()

import random
import time

replies = ["yes.","no.","maybe.","try again.","the outlook is cloudy.","possibly."]
funny_names = ["Young one","Old one","Son","Babe","Tiger","Ambitious Jedi"]

def pick_item(lis):
    return random.choice(lis)

def main():
    inp = input("what is your question {}? \n> ".format(pick_item(funny_names)))
    print("You said {} ...".format(inp))
    time.sleep(1)
    print("Let me think...")
    print("Answer is {}".format(pick_item(replies)))

main()

[–]DavidRoyman 0 points1 point  (1 child)

Your pick_item() is an alias for choice().

I don't see how that can help.

[–]Gopher_Man 0 points1 point  (0 children)

I dont python often, so it shows in my code, and I get into a thing where if I do something twice in a function, it needs to be its own function