tgspython Ответов: 1

Почему в python3 есть отступ?


Когда я запускаю свой код, есть своего рода отступ на "Q:", но не "A:". Вы знаете, почему это так? Это не мешает коду работать, он работает, но мне показалось бы более аккуратным, если бы они "Q:" и "A:" были в одной строке. Спасибо.

КОД:
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"]

----

ПОЛНЫЙ КОД:
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

----



ОТСТУП (КОГДА БЕЖАЛ):

Ну а как насчет этого:
 Q: What do you call a boomerang that won't come back?

A: A stick


Что я уже пробовал:

Я попробовал перепечатать текст. \n но все равно не получится. Я был бы вам очень признателен, если бы вы мне помогли. Спасибо.

1 Ответов

Рейтинг:
11

Thomas Daniels

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

print("a", "b") будет печатать a b с промежутком между ними. То же самое происходит и здесь: он печатает "как насчет этого" с новыми строками, затем пробел, затем шутку. Попробуйте вместо этого:
print("\nWell what about this:\n\n" + joke)


tgspython

Спасибо за вашу помощь, теперь она работает, я ее починил!