import random # List of jokes jokes = [ "Why don't scientists trust atoms? Because they make up everything!", "Why did the scarecrow win an award? Because he was outstanding in his field!", "Why don't skeletons fight each other? They don't have the guts.", "What do you call fake spaghetti? An impasta!", "Why did the bicycle fall over? Because it was two-tired!", "Why did the math book look sad? Because it had too many problems.", "What do you call cheese that isn't yours? Nacho cheese!", "Why can't you give Elsa a balloon? Because she will let it go!", "Why was the computer cold? It left its Windows open!", "What do you call a bear with no teeth? A gummy bear!" ] def tell_joke(): """Randomly selects and prints a joke.""" joke = random.choice(jokes) print("Here's a joke for you:") print(joke) # Main program if __name__ == "__main__": print("Welcome to the Random Joke Generator!") while True: user_input = input("Would you like to hear a joke? (yes/no): ").strip().lower() if user_input in ["yes", "y"]: tell_joke() elif user_input in ["no", "n"]: print("Alright, no jokes for now. Have a great day!") break else: print("Please enter 'yes' or 'no'.")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter