[英]Print slowly in terminal PYTHON
I was wondering if you could help me print slowly in Python.我想知道你能不能帮我在 Python 中慢慢打印。 We're tasked with writing a game for this course and I've done a very basic small intro but I want the text to print slower and I have no clue how to target single lines see code below.我们的任务是为这门课程编写一个游戏,我做了一个非常基本的小介绍,但我希望文本打印得更慢,我不知道如何定位单行,请参见下面的代码。 I'd like the print functions to print slower on some parts but when I code further I want some paragraphs that will be written later to print faster.我希望打印功能在某些部分打印速度较慢,但是当我进一步编码时,我希望稍后编写一些段落以更快地打印。 Can anyone give me a dumbed-down version to help an absolute beginner (I started 4 days ago with coding) Thanks in Advance!谁能给我一个简化的版本来帮助一个绝对的初学者(我 4 天前开始编码)提前致谢!
Escape_the_python = "Welcome to Escape the Python! What is your name?..."
print (Escape_the_python)
name = input("")
while True:
print (f"Welcome {name}. Are you ready to begin?")
begin = input ("")
if begin.lower() == ("yes".lower)():
print ("Let the game begin...")
break
elif begin.lower() == ("no".lower)():
print ("Type Yes when you're ready!")
else:
print ("Invalid option please try again.")
I think this is what You are looking for (btw did this for the first time, never even thought about this):我认为这就是您正在寻找的东西(顺便说一句,这是第一次这样做,甚至从未想过这个):
import time
sentence = 'hello world'
for char in sentence:
time.sleep(0.5)
print(char, end='')
0.5
represents seconds 0.5
代表秒
I usually make it like this.我通常是这样弄的。 Easy and customizable简单且可定制
import time
import sys
def slowPrint(string, speed=0.05):
for char in string:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(speed)
slowPrint('Hello World!', 0.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.