Inconsistent use of tabs and spaces in python program- pls help

Hi! I am making a countdown timer and it was going pretty well until on one line it said inconsistent use of tabs and spaces in indentation. Here is the code:

import time
def countdown(t): 
    """
    Countdown Timer
    """
    while t:
        mins, secs = divmod(t, 60) 
        hours, mins = divmod(mins, 60)
        days, hours = divmod(hours, 24)
        weeks, days = divmod(days, 7)
	years, weeks = divmod(weeks, 52)
        timer = '{:02d}:{:02d}:{:02d}:{:02d}'.format(days, hours, mins, secs) 
        print(timer, end="\r") 
        time.sleep(1) 
        t -= 1


    print('Yay! Your event came!') 
	
t = input("Enter number of seconds:\n")
mul1 = ""
mul2 = ""
if t == "I don't know":
	while mul1 != "0" and mul2 != "0":
		mul1 = input("What is the first number to multiply?  ")
		mul2 = input("What is the second number to multiply?  ")
		print(int(mul1) * int(mul2))
	t = input("Enter number of seconds:\n")
	countdown(int(t))
else:
	countdown(int(t))

Thanks to anybody who helps!
The error is at weeks, days = divmod(days, 7)

So Python has meaningful whitespace. So you need to have consistent amount of spaces and you have to stick to either only tabs or only spaces (there are some exceptions but please do this.)

As you can see, these three lines are indented differently. To fix that, just make them indented the same:

        weeks, days = divmod(days, 7)
        years, weeks = divmod(weeks, 52)
        timer = '{:02d}:{:02d}:{:02d}:{:02d}'.format(days, hours, mins, secs) 

And the error should go away.

1 Like

Thanks! I just made them all spaces.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.