Stuck in a while loop within a function (python) -
i'm trying find gender of user. code function:
def getgender(): """figure out gender of person.""" gender = input("are male or female? (m/f)").lower() while gender != "m" or "f": gender = input("are male or female? (m/f)").lower() return gender
when run keep getting stuck in loop, when input valid response. main code:
def main(): welcome() getgender() if gender == "m": malecalc() malefinding() else: femalecalc() femfinding() disclaimer() #run program main() input("\n\npress enter key exit.")
i've been trying figure out if problem function's while loop or if it's overall logic issue.
thanks help.
one issue in section:
gender != "m" or "f"
both "m" , "f" treated true in python, , so, != binds more tightly or, same as
(gender != "m") or "f"
which true.
try instead:
while gender != "m" or gender != "f":
or
while gender not in ("m", "f"):
Comments
Post a Comment