Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When I run my code there is a sort of indent at "Q:" but not "A:". Do you know why that is? It does not stop the code from running, it works, but it would look neater to me if they "Q:" and "A:" were both in line. Thanks.

CODE:
Python
jokes = ["Q: What do you call a boomerang that won't come back?\n\nA: A stick\n","Q: What's the difference between ‘Oooh’ and ‘Aaah’?\n\nA: About 3 inches\n","Q: Why do most women pay more attention to their appearance than improving their minds?\n\nA: Because most men are stupid but few are blind\n","Q: How do you tell a male chromosome from a female chromosome?\n\nA: Pull down its genes","Q: What do you call a fake spaghetti?\n\nA: An im-pasta\n","Q: What did the yoga instructor say to her landlord when he tried to evict her?\n\nA: Namaste\n","Q: What do you call a row of rabbits jumping backwards?\n\nA: A receding hare line\n","Q: What do you call a boomerang that won't come back?\n\nA: A stick\n","Q: What did one wall say to the other wall?\n\nA: I’ll meet you at the corner\n", "Q: What do you call a bear with no teeth?\n\nA: A gummy bear\n"]

----

FULL CODE:
Python
import time
import string
import random

def newjoke(joke):
    time.sleep(1)
    print ("\nWell what about this:\n\n",joke)
    time.sleep(0.5)
    
jokes = ["Q: What do you call a boomerang that won't come back?\n\nA: A stick\n","Q: What's the difference between ‘Oooh’ and ‘Aaah’?\n\nA: About 3 inches\n","Q: Why do most women pay more attention to their appearance than improving their minds?\n\nA: Because most men are stupid but few are blind\n","Q: How do you tell a male chromosome from a female chromosome?\n\nA: Pull down its genes","Q: What do you call a fake spaghetti?\n\nA: An im-pasta\n","Q: What did the yoga instructor say to her landlord when he tried to evict her?\n\nA: Namaste\n","Q: What do you call a row of rabbits jumping backwards?\n\nA: A receding hare line\n","Q: What do you call a boomerang that won't come back?\n\nA: A stick\n","Q: What did one wall say to the other wall?\n\nA: I’ll meet you at the corner\n", "Q: What do you call a bear with no teeth?\n\nA: A gummy bear\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(1.5)
print ("Q: What's the point in pushing an envelope?\n\nA: There'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

----



THE INDENT (WHEN RAN):

Well what about this:
 Q: What do you call a boomerang that won't come back?

A: A stick


What I have tried:

I have tried re-typing the \n but still won't work. I'd appreciate it if you could help me out. Thanks.
Posted
Updated 27-Jan-18 6:21am
v3

1 solution

Python
print("\nWell what about this:\n\n",joke)

print("a", "b") will print a b with a space in-between. That's what's happening here too: it prints the "What about this" with the newlines, then a space, then the joke. Try this instead:
Python
print("\nWell what about this:\n\n" + joke)
 
Share this answer
 
Comments
tgspython 27-Jan-18 13:38pm    
Thank you for your help, it works now, I've fixed it!

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