【发布时间】:2018-08-10 05:09:59
【问题描述】:
好的,所以我的 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.''')
两次,我只需要写一次。
【问题讨论】:
-
请粘贴您的代码,而不是您的代码图像!
-
我有一个问题,为什么你在接受输入之后打破循环然后处理相同的输入?
-
编程中有一个重要的原则,称为 DRY 代码。 en.wikipedia.org/wiki/Don%27t_repeat_yourself 您的代码重复次数过多。你应该阅读更多关于函数的内容。
标签: python python-3.x