def getSex():
while True:
sex = input('Digite seu sexo:')
if sex == 'M' or sex == 'F':
return sex
print(getSex())
#https://pt.stackoverflow.com/q/257173/101
ZGVmIGdldFNleCgpOgogICAgd2hpbGUgVHJ1ZToKICAgICAgICBzZXggPSBpbnB1dCgnRGlnaXRlIHNldSBzZXhvOicpCiAgICAgICAgaWYgc2V4ID09ICdNJyBvciBzZXggPT0gJ0YnOgogICAgICAgICAgICByZXR1cm4gc2V4CgpwcmludChnZXRTZXgoKSkKCiNodHRwczovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvMjU3MTczLzEwMQ==