Calling Functions in Python 3

Asked

Viewed 832 times

1

Hello, I was "playing" without Python, and I decided to make a minigame, for the PC to play Jokempô with me (I AM BEGINNER IN PROGRAMMING).

while pj <5 and pc <5:
def game()

But I came across the following problem.

def game()
         ^ SyntaxError: invalid syntax

Can someone tell me where I went wrong?

  • 1

    The keyword def is used to define a function, not to call it. If you just want to invoke the function, use game(). Be careful with code indentation.

1 answer

1

The structure blocks in python are made by indentation. So if you want to make a loop with the game function, must identar 4 spaces before your call.

while pj <5 and pc <5:
    game()

Also for the function game() function, must be declared before your call.

def game():
    # instruções da função

# bloco do while

Browser other questions tagged

You are not signed in. Login or sign up in order to post.