Christian Christian - 4 months ago 9
Python Question

Syntax error when defining 2 functions in python

I've very new to programming so sorry if this is a stupid question, but I'm trying to make a program with multiple functions, but whenever I attempt to define one it comes up with an error.

def startUp():
promptName()

def promptName():
name = input("Hello. Please enter your name: ")

startUp()
SyntaxError: invalid syntax


If it helps the def part in def promptName(): is highlighted red.

Answer

I'd bet you're trying to paste the entire thing into a Python interpreter session. The command line interpreter needs things entered one block at a time, so try pasting the startUp function, hit enter, then promptName and enter, and then run the whole thing with the last line.

Alternatively, save it all as a .py file and run the file.

Comments