Lichtspielhaus
Lichtspielhaus

Reputation: 13

What's wrong with while loop?

def clock():
    import time
    m = 0
    s = 0
    while(True):
        if((m<60) and (s<60)): print(m,":",s)
        elif(s==60):
            s == -1
            m += 1
        elif(m==60):
            print("It's been 1 hour m8")
            break
        s += 1
        time.sleep(1)

Result is, it counts until 0:59 then stops. It suppose to go until 59.59. I want to understand the fundemantal looping mistake which i did in here, thanks.

Upvotes: 0

Views: 56

Answers (1)

jerrycheng
jerrycheng

Reputation: 167

s == -1

Does nothing here. Change it to

s = -1

Upvotes: 2

Related Questions