如何在python中添加进度条?

时间:2014-04-06 20:22:26

标签: python

我被要求制作一个特权检查工具'到目前为止它的表现相当不错。这是我的代码:

def Privilige():
     print("Welcome to Privilege checker V0.011")
     print("Would you like to check your privileges?")
     answer = input("Type 'Yes' or 'No' and hit enter ('Y', 'y', 'N', or 'n' are also valid choices).")
     print("Checking priviliges.")
     if answer == "yes" or answer == "Yes" or answer == "Y" or answer == 'y':
         print("Privileges: Checked")
     elif answer == "no" or answer == "No" or answer == 'N' or answer == 'n':
         print("Privileges: Unchecked.")
     else:
          print("Please enter a valid option.")
Privilige()

现在,在print("Checking privileges.")if answer == "yes"之间,我想添加一个使用此字符的进度条,"█"这可能吗? 感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

from time import sleep

for i in range(60):  # Change this number to make it longer or shorter.
    print('█', end='')
    sleep(0.1)  # Change this number to make it faster or slower.