heya guys - new to posting here, but i have browsed the forums for help over this year so far. obvisoulsy im also new to python, only trying it since march.
Im trying to write some code for a 'knock knock' program. It uses a txt file for the jokes, prompts the user at the appropriate points. All this is working fine - however I'm supposed to randomise the jokes.
Im guessing I should be using random shuffle for this. I just cant get it to work. Should I be setting the shuffle up in it's own def, or can it be part of main?? I had a bit of a play with this and no success.
Anyway - heres the working code so far - any hints as to where my shuffle needs to appear would be great ~ :)
def main(): k = open("knockknock.txt", "r") line = k.readline() while len(line)!=0: joke = line.split(',') comeback = joke punchline = joke print "\nKnock Knock\n" if raw_input("""\nEnter choice: 0 : Who's there? 1 : Go away!\n""")=="0": print comeback else: print "\nOK, cya!" break print """\nEnter choice: 0 :""",comeback,"""who? 1 : Go away!\n""" if raw_input()=="0": print punchline else: print "\nOK, cya!" break print "bwahahahahaha\n\n" if raw_input("Can you handle another (Y/N)? ").upper() == "N": print "\nOK, cya!" break else: line = k.readline() main() raw_input("\n\npress ENTER to continue")
Edited by vegaseat: added code tags