Python-打字机功能不起作用。大量延迟后打印整串

发布于 2025-02-10 05:34:41 字数 499 浏览 0 评论 0原文

我目前正在学习Python,并且遇到了类型的作者效果。但是,当我应用代码时,它似乎不起作用。我感谢某人对为什么不起作用的看法。

当我运行代码时,它对3-4秒无能为力,然后打印WHOE字符串。我希望它在打印下一个角色之前,将单个角色打印出一个小延迟的时间。

import string

def typewriter_simulator(message):
    for char in message:
        print(char, end='')
        if char in string.punctuation:
            time.sleep(1)
        time.sleep(.03)
    print('')


def print_pause_type(message, delay=1):
    typewriter_simulator(message)
    time.sleep(delay)

print_pause_type("Hello!")

I am currently learning Python and I came across a type writer effect. But when I apply the code it does not seem to work. I would appreciate someone to provide their view as to why this does not work please.

When I run the code it does nothing for 3-4 secs then prints the whoe string. I am wanting it to print individual character a time with a small delay before printing the next character.

import string

def typewriter_simulator(message):
    for char in message:
        print(char, end='')
        if char in string.punctuation:
            time.sleep(1)
        time.sleep(.03)
    print('')


def print_pause_type(message, delay=1):
    typewriter_simulator(message)
    time.sleep(delay)

print_pause_type("Hello!")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文