如何在Python3中链接两条路径?

如何在Python3中链接两条路径?,python,python-3.x,Python,Python 3.x,好的,在一个问题之后,我的python代码中有两条独立的路径,我需要它们链接在一起,以避免重复键入游戏的其余部分,并浪费空间和代码 如您所见,最后四行左右是相同的,但有两个不同的缩进。我怎样才能使它们都一样呢?因此,与其写下: print('''You carefully wrap the material around your head, wincing in pain everytime your hand bumps the wound.''') print('''You wonder

好的,在一个问题之后,我的python代码中有两条独立的路径,我需要它们链接在一起,以避免重复键入游戏的其余部分,并浪费空间和代码

如您所见,最后四行左右是相同的,但有两个不同的缩进。我怎样才能使它们都一样呢?因此,与其写下:

print('''You carefully wrap the material around your head, wincing in pain everytime your hand bumps the wound.''')
print('''You wonder what the wound was from. It is unimportant however as the bleeding seems to be slowing.''')

两次,我只需要写一次。

在这种特殊情况下,您可以为
yeet\u bleed
提供默认值。e、 g

yeet_bleed = 0
# Some input to yeet_bleed here
if bleeding_heal == '1' or yeet_bleed == '1':
    print('something')
关于
while True
循环的另一个建议:

while bleeding_heal not in ['1','2','3']:
    bleeding_heal = input("some text:")
使用函数:

def rip_and_bandage():
    print('''You carefully wrap the material around your head, wincing in pain everytime your hand bumps the wound.''')
    print('''You wonder what the wound was from. It is unimportant however as the bleeding seems to be slowing.''')

在每个路径之后对公共函数进行函数调用,或者在函数中编写路径代码,一旦函数返回,就会执行公共代码块

尽量不要使用多个和嵌套,如果会使代码混淆-使用句柄函数-下面链接中建议的解决方案:


请粘贴您的代码,而不是代码的图像!我有一个问题,为什么你在接受输入后要打破循环,然后处理相同的输入?编程中有一个重要的原则,叫做干代码。你的代码有太多的重复。你应该多读一些关于函数的知识。