My code says I'm wrong but my teacher did the same thing and it worked for her

Question:
What am I doing wrong?

Current behavior:
When I try to run it, it says:

  File "main.py", line 42
    if(stopping):
                ^
IndentationError: unindent does not match any outer indentation level

I don’t know what is going on
Desired behavior
I would like it to work.

Repl link:
https://replit.com/@blablayay/Pig-dice-game?v=1

code snippet

Hello, I can see there is a spacing error there, as the error mentioned.
In line 40 of your code you used 2 spacing (4 spaces) and without anything between them in line 42, which is

if(stopping):

you used 1 spacing(2 spaces) instead. Python complied cannot find the ending of the line 40 as line 42 doesn’t have the same (spacing) level with line 40

I recommend you to remove 2 spaces, which is pressing backspace 1 time in this repl IDE, in line 40 before the

stopping = True

So the if statement in line 42 won’t be affected.

1 Like

Its not easy to see (possibly a feature suggestion to Replit IDE) but there are 2 types of indentation…

  • Spaces (these can be single, double, triple or even quadruple)
  • Tabs (depending how the IDE is setup, sometimes using the tab key can insert space type indentation)

These types can sometimes be mixed up and certain languages that rely on indentation such as Python will throw an error if that is the case.

In your case, clicking the auto-format button in the repl (the one next to the 3 dots in the top right corner) should fix your issue.

image

If not, you can always run it through a different formatter like Online Python Formatter.

2 Likes

IDK Where Is Problem But When I Coded Your Code Manually Again Then I Don’t See Any Error

Codes :

from random import randint

maxScore = 100
player0Safe = 0
player1Safe = 0

player = 0
score = 0
safe = 0

stopping = False

while (player0Safe < maxScore) and (player1Safe < maxScore):
  if player == 0:
    safe = player0Safe
  else:
    safe = player1Safe

  print(f'Player: {player}')
  print(f'Safe Score {safe}')
  print(f'Rolling Score: {score}')
  print()

  rolling = input('Do you want to roll or stay? Enter R for Roll, S for Stay.').lower()

  if rolling == 'r':
    rolledNumber = randint(1,6)
    print('Rolled ' + str(rolledNumber))
    if rolledNumber == 1:
      print(f'You lost {score} points. You keep your previous points: {safe}')
      stopping = True
      score = 0
    else:
      score = score + rolledNumber
  else:
    stopping = True
    if(stopping):
      if(player == 0):
        player0Safe = player0Safe + score
      else:
        player1Safe = player1Safe + score
      print()
      print('Your total score is: ' + str(safe+score))
      print()

    score = 0
    stopping = False
    player = (player+1) % 2

if(player0Safe >= maxScore):
    print('Player 0 wins with a score of ' + str(player0Safe) + '!')
else:
    print('Player 1 wins with a score of ' + str(player1Safe) + '!')

It is because the problem occurs here.
Your code is having

…
else:
    stopping = True
    if(stopping):
        if(player == 0):
…

While his code is having

…
else:
  stopping = True
    if(stopping):
        if(player == 0):
…

The little spacing missing in front of

stopping = True

Made the entire error