我如何在保持重复功能的同时重复代码

问题描述 投票:-3回答:1

我想重复以下代码,同时保持重复功能的目的,而不仅仅是重复打印'...'五次:

import time
import sys


for i in range(0,5):
    blah =  "...\n"
    for h in blah:
    sys.stdout.write(h)
    sys.stdout.flush()
    time.sleep(0.5)

错误消息:

    File "File.py", line 8
        sys.stdout.write(h)
        ^
IndentationError: expected an indented block
python repeat
1个回答
0
投票

请,而不是:

blah =  "...\n"
for h in blah:
sys.stdout.write(h)

只做:

blah =  "...\n"
sys.stdout.write(blah)
© www.soinside.com 2019 - 2024. All rights reserved.