所以我对python来说还很陌生,所以我尝试制作此加载屏幕:

import time

loading1 = "loading."
loading2 = "loading.."
loading3 = "loading..."
random1 = 0

while random1 < 10:
    print(loading1 + "\r", end = "")
    time.sleep(1)
    random1 += 1

    print(loading2 + "\r", end = "")
    time.sleep(1)
    random1 += 1

    print(loading3 + "\r", end = "")
    time.sleep(1)
    random1 += 1


但它在第一次“加载...”后一直挂着
但它应该重复10次,我在这里做错了什么?

最佳答案

它看起来只是挂着的,实际上是当您返回循环的开头时,在loading.之上编写loading...。但是没有任何东西可以去除其后的多余点,因此您看不到区别。

loading1的末尾添加空格,以便在重复循环时将清除上一个迭代中的第二个和第三个.

import time

loading1 = "loading.  "
loading2 = "loading.."
loading3 = "loading..."
random1 = 0

while random1 < 10:
    print(loading1 + "\r", end = "")
    time.sleep(1)
    random1 += 1

    print(loading2 + "\r", end = "")
    time.sleep(1)
    random1 += 1

    print(loading3 + "\r", end = "")
    time.sleep(1)
    random1 += 1

关于python - python循环一行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54260968/

10-11 10:51