0

So I am just getting started with Python and I was practicing on Codewars. I was doing this kata, that I forgot the name of. I wrote the code going if, while and another if deep. I got this error:

else:
        ^
TabError: inconsistent use of tabs and spaces in indentation

I saw nothing wrong with the code and the else was aligned with the if.

# our parameters are h - the height from where the ball is falling,
# bounce - the percent of bounce out of 1.0, window - where teh mother is (1.5 m)
# HOW MANY TIMES DID THE BALL GO IN FRONT OF THE WINDOW
# Float parameter "h" in meters must be greater than 0
# Float parameter "bounce" must be greater than 0 and less than 1
# Float parameter "window" must be less than h.

def bouncingBall(h, bounce, window):
    current_bounce = h
    times_seen = None
    if h > 0 and bounce > 0 and bounce < 1 and window < h:
        while current_bounce_height > window:
            current_bounce_height = current_bounce_height * bounce
            if times_seen >= 1:
                times_seen = times_seen + 2
            else:
                times_seen = times_seen + 1
        print(times_seen)
        return times_seen
    else:
        print(-1)
        return -1

bouncingBall(10, 0.66, 1.5)

And the code may have other mistakes, as I said just getting started. Don't pay those any attention.

  • The error message is straightforward: your indentation mixes tabs and spaces. Python requires you to be perfectly consistent in your usage, and you were not. Just fix your white space, and the problem will go away. – Prune Apr 21 '20 at 22:11
  • 2
    See: https://stackoverflow.com/questions/5685406/inconsistent-use-of-tabs-and-spaces-in-indentation – Mark Apr 21 '20 at 22:11
  • 1
    Also, please repeat [MRE](https://stackoverflow.com/help/minimal-reproducible-example) from the intro tour. Posting code with multiple problems is not nice to the rest of us. – Prune Apr 21 '20 at 22:12
  • 1
    Of course we can't see it, how do you propose to distinguish between spaces and tabs by looking at them? But your editor might have a "detab" option/command that replaces all tabs by appriopriate number of spaces; try doing that. – Błotosmętek Apr 21 '20 at 22:18
  • actually dunno what happened but my editor just became woke and is now good with the code – Tomáš Čikovský Apr 21 '20 at 22:24

0 Answers0