Trouble Setting a Variable True basing on an Imput - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Trouble Setting a Variable True basing on an Imput (/thread-20248.html) |
Trouble Setting a Variable True basing on an Imput - VictorVictus - Aug-02-2019 Hello guys! I am currently working in a Little test again, which at one step requires an imput, simple, right? Well I have two variables, a OwnerMale and OwnerFemale, which are both set in False when you execute the .py My question is this one: Can I make my program have a list of Names which when you write them down in imput, the program searches for the list of names and basing on the name sets OwnerMale or OwnerFemale as true? And if this is posible, could I also include a question calling for confirmation if the name is female and basing on "Yes" or "No" set the OwnerMale and OwnerFemale accordingly? Thank you. Here's my code if Male == True and IsMale == True: print("My Name has been set, i'm Programmed a Male Bot, what is your name?") OwnerName = input("Write your name.") RE: Trouble Setting a Variable True basing on an Imput - ichabod801 - Aug-02-2019 I'm not sure I understand the question. But I think you want to check if a name is already in a list of names? >>> boy_names = ['Bob', 'Arthur', 'Kevin'] >>> 'Arthur' in boy_names True >>> 'Jane' in boy_names FalseAlso, you don't need to test if something is equal to True, you can just test that thing directly. So you could do: if Male and IsMale: print("My Name has been set, i'm Programmed a Male Bot, what is your name?") OwnerName = input("Write your name.") RE: Trouble Setting a Variable True basing on an Imput - VictorVictus - Aug-02-2019 (Aug-02-2019, 01:58 PM)ichabod801 Wrote: I'm not sure I understand the question. But I think you want to check if a name is already in a list of names? What I want to do is to make the program check a list with names, and if it shows up in one of the lists automatically check the name as male or female RE: Trouble Setting a Variable True basing on an Imput - ichabod801 - Aug-02-2019 (Aug-02-2019, 03:27 PM)VictorVictus Wrote: What I want to do is to make the program check a list with names, and if it shows up in one of the lists automatically check the name as male or female I'm still confused. You want to check "a list", and then if it shows up "in one of the lists" do something. Is it one list or multiple lists? And what do you mean by "check the name male or female"? The name in the list, or the name the user gave you? Can you give me a small example of the lists you are talking about? RE: Trouble Setting a Variable True basing on an Imput - SheeppOSU - Aug-02-2019 (Aug-02-2019, 03:27 PM)VictorVictus Wrote: What I want to do is to make the program check a list with names, and if it shows up in one of the lists automatically check the name as male or femaleI'm pretty sure what you want to do is try to determine their gender based on their name. If I'm correct there are two options. Make a dictionary or two lists Option 1: NameDict = { 'Male' : ['andrew', 'Nick'], 'Female' : ['elizabeth', 'Mary'] } name = input('Type your name').lower() Gender = None for gender in NameDict: if name in NameDict[gender]: Gender = gender if gender == None: print('Name not found') else: print('Name found are you %s?' %Gender)Option 2: FemaleNames = ['elizabeth', 'Mary'] MaleNames = ['Andrew', 'Nick'] name = input('Type your name? ').lower() Gender = None if name in FemaleNames: Gender = 'Female' elif name in MaleNames: Gender = 'Male' if gender == None: print('Name not found') else: print('Name found are you %s?' %Gender)Hope this helps! RE: Trouble Setting a Variable True basing on an Imput - VictorVictus - Aug-02-2019 (Aug-02-2019, 05:07 PM)ichabod801 Wrote:(Aug-02-2019, 03:27 PM)VictorVictus Wrote: What I want to do is to make the program check a list with names, and if it shows up in one of the lists automatically check the name as male or female thanks for your help, doubt has been solved already, still I thank you! I intended to make two lists of names and if they coincided with the imput they would be classified as either male or female. |