我一直在做一个RPG游戏,我喜欢系统标准输出写入()和.flush()使其具有键入字母的效果。但是当我把一个变量输入到我想输入的句子中时,它不会输出句子的任何一部分,甚至连我在引号中的部分(非变量)也不会。我想知道是否有一种方法可以避免我为变量和引号中的内容编写单独的代码块,或者让它键入变量。在
if girl1 == True:
t="You and",girl1realname,"have found a sandy beach while looking for a
place of shelter. \nWhether you look left or right, the beach ranges for
miles.\n"
y=girl1realname+": 'Hey, I guess I always wanted a house on the beach...I
think. I can't really remember.'\n"
for char in (t):
time.sleep(0.05)
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(1)
for char in (y):
time.sleep(0.05)
sys.stdout.write(char)
sys.stdout.flush()
在
t
的定义中,逗号将使其成为一个元组。迭代,然后一次写入每个块("You and"
,girl1realname
,和"have found..."
),而不是每个块中的每个字符。将逗号替换为+
。在你对
y
的定义似乎很好。在至于重用,您可以定义一个函数,如:
使用方式:
^{pr2}$相关问题 更多 >
编程相关推荐