为什么在python3中有一个缩进? [英] Why is there an indent, in python3?
问题描述
当我运行代码时,在"Q:"处有某种缩进,但在"A:"处没有缩进.你知道那是为什么吗?它不会阻止代码运行,它可以工作,但是如果它们"Q:"和"A:"都符合要求,对我来说看起来会更整洁.谢谢.
代码:
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:
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:
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
----
指数(当RAN时):
那么呢:
----
THE INDENT (WHEN RAN):
Well what about this:
Q: What do you call a boomerang that won't come back?
A: A stick
我尝试过的事情:
我尝试重新键入\n
,但仍然无法正常工作.如果您能帮助我,我将不胜感激.谢谢.
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.
推荐答案
print("\nWell what about this:\n\n",joke)
print("a", "b")
将打印a b
,中间有一个空格.这也是这里发生的事情:它用换行符打印关于此事的内容",然后是空格,然后是笑话.尝试以下方法:
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:
print("\nWell what about this:\n\n" + joke)
这篇关于为什么在python3中有一个缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!