def
is a language for constructing the language, it is not a function, it is used to declare and define a function.
Your code, because of the posted indentation, does not do what you want, Python is sensitive to indentation. Then
def se():
sex = input('Digite seu sexo:')
is the function e
while sex != 'M' and sex != 'F':
It's a loose code.
What you probably want is this:
def getSex():
while True:
sex = input('Digite seu sexo:')
if sex == 'M' or sex == 'F':
return sex
print(getSex())
See working on ideone . Also I put GitHub for future reference.
The return
closes a function and it can optionally deliver a result to the caller, as every mathematical function does (programming does not invent anything, it's all math, almost everything taught in school). >
Of course there is a lot to improve on this, but the focus of the question is this.