Use Python to realize reading progress bar display

1. Encountered a problem

Every time I read a book, I always want to know what my reading progress bar is, but I have no choice but to use a calculator to calculate the number of pages I have read/total number of pages to get the corresponding percentage.

First, the calculation is troublesome, and second, there is no intuitive progress bar.

So I wondered if I could use Python to make a reading progress bar record.

2. Code writing

def bar(n,m):
    jd='\r %2d%% [%s%s]'
    n1=int(n*20/m)
    m1=int(m*20/m)
    a = '■' * n1
    b = '□' * (m1 - n1)
    c = (float(n / m)) * 100
    print(jd % (c, a, b), end='')
    print("明天继续阅读哦,主人加油!")


print("主人你好,今天又看书啦!")
Book_Number=int(input("这本书多少页:"))
Readed_Number=int(input("主人你已读多少页:"))

bar(Readed_Number,Book_Number)




3. Complete the effect

insert image description here

Guess you like

Origin blog.csdn.net/Gnewocean/article/details/91663543