Python下载脚本

Python下载脚本,python,python-3.x,Python,Python 3.x,当我运行这个时,进度%是向后的,有人知道如何在开始时使其为0%,在完成时使其为100%吗 import time x = 25 y = x t = 0 downloading = True while downloading: time.sleep(1) t += 1 x -= 1 f = ((x/y) * 100) print('Time:', str(t) + ',', 'Progress: ', '{0:.2}'.format(str(f)) + '%,', 'Re

当我运行这个时,进度%是向后的,有人知道如何在开始时使其为0%,在完成时使其为100%吗

import time

x = 25
y = x
t = 0

downloading = True
while downloading:
  time.sleep(1)
  t += 1
  x -= 1
  f = ((x/y) * 100)
  print('Time:', str(t) + ',', 'Progress: ', '{0:.2}'.format(str(f)) + '%,', 'Remaining: ' + str(x), 'MB', end="\r")

  if(x == 0):
    print('\nComplete!')
    break
只需使用
(1-x/y)
而不是
f
中的
x/y

import time

x = 25
y = x
t = 0

downloading = True
while downloading:
  time.sleep(0.01)
  t += 1
  x -= 1
  f = ((1-x/y) * 100)
  print('Time:', str(t) + ',', 'Progress: ', '{0:.3}'.format(str(f)) + '%,', 'Remaining: ' + str(x), 'MB', end="\r")

  if(x == 0):
    print('\nComplete!')
    break

另外请注意,您应该使用
“{0:.3}”。格式(str(f))
,以便
100%
可以正确显示。

完美!非常感谢您的回答,很抱歉我是python新手,正在学习:)