好的,在一个问题之后,我的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_bleed
提供一个默认值。e、 g关于
while True
循环的另一个建议是:使用函数:
在每个路径之后,对公共函数进行函数调用,或者在函数中编写路径代码,一旦函数返回,就会执行公共代码块。你知道吗
尽量不要使用多个和嵌套的如果,使代码混淆-使用句柄函数-建议在下面的链接中使用解决方案:
What's an alternative to if/elif statements in Python?
相关问题 更多 >
编程相关推荐