好吧,所以我在提问后在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.''')
两次,我只需要写一次。
答案 0 :(得分:0)
在这种情况下,您可以为yeet_bleed
提供默认值。例如
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:")
答案 1 :(得分:0)
使用功能:
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.''')
答案 2 :(得分:0)
在每个路径之后对函数进行函数调用,或在函数中编写路径代码,函数返回后,将执行您的公共代码块。
如果下面的链接中建议使用以下功能,请尽量避免使用多个和嵌套的代码:-使用句柄功能-解决方案: