python – TypeError (function return None)

from tkinter import *

app=Tk()
app.title("progress")
app.geometry("800x500+365+120")

q={'weigh':100,'goal':75,'now':86} #or 'now':93

def bar():
    first=int(q['weigh'])
    achieve=int(q['goal'])
    today=int(q['now'])

    def num(n):
        for z in range(0,n):
            y=(first-achieve)*(z/100)
            if (first-today)==y:
                return z
            if today<achieve:
                z=100
                return z
    rate=int(num(101)/10)
    for _ in range(1,rate+1):
        Entry(app,bg="blue",width=4).pack(side=LEFT)
    for _ in range(rate,10):
        Entry(app,width=4).pack(side=LEFT)

Button(app,text="OK",command=bar).pack()
app.mainloop()
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

all number except 86 and 93 works well.
Only 86 and 93 occur TypeError.
But I want to use 86 and 93 to include all number. What should I do?

Product of the Month September 2016

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *