-1

Input

yourChoice = True

while yourChoice:
    inf_or_ltd = input('Would you like to play infinte or a limited game?: '):
        if inf_or_ltd = ((('Limited') or ('limited')) and (compScore == ('3'))):
            exit = True
            print("You lost, Goodbye")
            break
            time.sleep(1)

Why is the colon a invalid syntax? I've checked the bracket balance and the previous lines (which are just variables and importing a few modules). It says that a limited game?: '): is invalid syntax.

halfer
  • 19,824
  • 17
  • 99
  • 186
Eyebuster234
  • 11
  • 1
  • 3
  • 1
    `input(..):`, why do you write a colon after `input`? Furthermore note https://stackoverflow.com/questions/15851146/checking-multiple-values-for-a-variable – Willem Van Onsem Dec 16 '17 at 19:09
  • 1
    You wouldn't write `a = 2:`, would you? See also. https://stackoverflow.com/q/215581/8881141 – Mr. T Dec 16 '17 at 19:11
  • Oh, it was the two mistakes you guys mentioned. It was some small mistake, like I thought it would be. Anyway, thanks for the help :) – Eyebuster234 Dec 16 '17 at 20:35

1 Answers1

1

In Python, a colon : defines the start of a scope block, it's essentially the same as { in most languages. But the colon isn't enough, scope blocks also need to be idented. The amount of identation depends on the parent block.

scope1:
    scope2:
        scope3:

A block ends when its identation ends, i.e.:

scope1:
    scope1_statement
    scope2:
        scope3:
            scope3_statement
        scope2_statement
    scope1_statement

Now, when would you create a new scope block? Well, you create them when you need to define a new scope, such as:

  • Declaring new methods (def, lambda, ...)
  • Declaring new code branches (if conditions, try-catch...)

In your scenario, you are trying to create a new scope after a statement (an instruction) which in this case is an assignment inf_or_ltd = input('...').

Python instructions cannot create a new scope block.

You need to place your if on the same identation as the above assignment;

inf_or_ltd = input('...')
if inf_or_ltd == anything:
     # do something
else:
     # do something else
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154