简体   繁体   English

我不能停止我的“程序”到特定的打印,它只是继续

[英]I can't stop my "program" to a specific print, it just goes on

There is an issue I'm having, it's a small story I'm, this has been frustrating me for hours now, help me!我遇到了一个问题,这是一个小故事,这让我沮丧了好几个小时,帮帮我!

if qsg_1 == "A":
    print ("Amazing, let's begin...")
elif qsg_1 == "B":
    print ("Goodbye, sinner.")

print(".")
print(".")
print(".")
print(".")
print(".")
print(".")
print("A tree is behind you.")

This seemed fine to me, but whenever I went and chose option B after opening the .py, this happened:这对我来说似乎很好,但是每当我在打开 .py 后选择选项 B 时,就会发生这种情况:

Okay user. Would you like to start this amazing journey?
[A] No. [B] Yes. [A/B]: B
Goodbye, sinner.
.
.
.
.
.
.
A tree is behind you.

I want to stop the "elif qsg_1 == "B": to print ("Goodbye, sinner."). I have tried to, although it's as if B was A, so even the:我想停止“elif qsg_1 ==“B”:打印(“再见,罪人。”)。我已经尝试过,虽然好像B是A,所以即使是:

print(".")
print(".")
print(".")
print(".")
print(".")
print(".")
print("A tree is behind you.")

appears, which has been getting me for hours now, I want the B option to end at print ("Goodbye, sinner") whenever I choose it, how do I do that?出现,这已经让我好几个小时了,我希望 B 选项在我选择它时以打印结束(“再见,罪人”),我该怎么做? Help!帮助!

Python uses indentation to control what gets executed when. Python 使用缩进来控制什么时候执行。 Consider the following:考虑以下:

if qsg_1 == "A":
    print ("Amazing, let's begin...")
    print(".")
    print(".")
    print(".")
    print(".")
    print(".")
    print(".")
    print("A tree is behind you.")
elif qsg_1 == "B":
    print ("Goodbye, sinner.")

Here, many print statements are under condition A, indented, so it is a good visual way to show what happens if condition A holds.在这里,许多print语句都在条件 A 下进行了缩进,因此这是一种很好的直观方式来显示条件 A 成立时会发生什么。 The same for B. B 也一样。

Put you code to function and add return after printing B case将您的代码置于功能并在打印B案例后添加return

def my_fn():
    if qsg_1 == "A":
        print ("Amazing, let's begin...")
    elif qsg_1 == "B":
        print ("Goodbye, sinner.")
        return

    print(".")
    print(".")
    print(".")
    print(".")
    print(".")
    print(".")
    print("A tree is behind you.")


my_fn()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM