Ask coding questions

← Back to all posts
Syntax error where there is none.
DUN0040 (2)

https://repl.it/@DUN0040/A-Basic-Bitlife
It says on line 38 at the last bracket that it is an invalid syntax where it isn't unless I am forgetting something because in my game it's supposed to be like bit life where it kills you at a random age so if someone could help I would be indebted.

Answered by JustARatherRidi (191) [earned 5 cycles]
View Answer
Commentshotnewtop
JustARatherRidi (191)

The problem in line 38 is that you haven't put a colon after the condition in your while loop. And after the colon, you should also indent all the code you want to be inside the loop.

However, there are actually quite a few other things wrong with the code.

  • First off, you don't write int(5), you just write 5. Saying int(5) means you're passing 5 (which is already an int) to int which gives you back the same 5 you put in. As you can see, that doesn't make much sense.
  • At line 195, you say from goto import *, which is unnecessary because you already did that at the beginning of the script.
  • At lines 194, 215, and 391, the if statements aren't indented right.
  • The range function takes either 1, 2, or 3 arguments.
    • If there is one argument, then that is the last number and 0 is the first.
    • If there are 2, then the first argument is the first number and the second argument is the last number.
    • With 3 arguments, it works just like 2, except that the last number is the difference between any two consecutive numbers (by default that is 1). For example, range(1, 10, 2) gives you [1, 3, 5, 7, 9]
  • So you can't say range(0, 1, 2, 3) like you do at line 35. You might be looking for [0, 1, 2, 3], which is the same as range(4).
  • Similarly, you also can't say random.randint(0,1,2,3) at line 36, because randint takes in 2 arguments, the first being the minimum value of the random number and the second being the maximum value of the random number. If you're trying to get a number between 0 and 3, you should do random.randint(0, 3)

These are just the ones I spotted right away, There are actually quite a bit more.

If you did make this game, I'd recommend testing out things more often. Otherwise, you'll end up with bugs like these that are much harder to fix later on.

ash15khng (463)

You're actually missing the colon there.