Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using Python3 and I'm writing this code where it tells you a joke and asks the user if they like it. If yes, then it will print something then the program is finished. If no it will keep on telling new jokes randomly until the user says 'yes'. However, the program does run wihtout any errors, so I'm not sure what the problem is.

here's my code:
Python
import time
import string
import random

def newjoke(joke):
    time.sleep(1)
    print ("Well what about this:\n\n",joke)

    time.sleep(0.5)
    funny = input("Did you find that funny?").lower()

    return funny

jokes = ["What do you call a boomerang that won't come back?\n\nA stick\n","What's the difference between ‘Oooh’ and ‘Aaah’?\n\nAbout 3 inches\n","Why do most women pay more attention to their appearance than improving their minds?\n\nBecause most men are stupid but few are blind\n","How do you tell a male chromosome from a female chromosome?\n\nPull down its genes","What do you call a fake spaghetti?\n\nAn im-pasta\n","What did the yoga instructor say to her landlord when he tried to evict her?\n\n'Namaste'\n"]

print ("Welcome to the Joke game")
time.sleep(1)
print ("You will be told a joke and it's answer")
time.sleep(1)
print ("Then you have to put in if you found it funny or not - yes/no\n")
time.sleep(3)

print ("What's the point in pushing an envelope?\n\nThere's no point because it's always going to be stationary!\n")

while True:
  
    time.sleep(3)
    funny = input("\nDid you find that funny?\n").lower()

    if funny == "no":
        joke = random.choice(jokes)
        funny = newjoke(joke)

    if funny == "yes":
      time.sleep(0.5)
      print ("\nI know, I'm a comedian")
      break


---

As you can see in the variable jokes I have a few jokes there (I am going to add more) but when I run the code after 2/3 enters of 'no' it displays blank/nothing then asks if I found it funny. Can you please help me, thanks.

What I have tried:

I have tried to replace the jokes with something shorter eg: "yo","lol","fun" and see if I could identify the problem. But the same thing happened.

I have also tried re-typing it, making sure there's no extra spaces or quotation marks.

So if anyone knows how to fix this, it would be much appreciated.
Posted
Updated 27-Jan-18 4:02am
v2

1 solution

Both newjoke and the code in the while loop will ask "Did you find that funny?". So, what you see is the question getting repeated because after newjoke get called, you'll go back to the beginning of the while loop. This gives the impression of displaying a blank joke, but you just didn't hit the code to generate a joke.
 
Share this answer
 
Comments
tgspython 27-Jan-18 11:50am    
Thank you so much for you help! I fixed it and it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900