Python Forum
Trouble Setting a Variable True basing on an Imput
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble Setting a Variable True basing on an Imput
#1
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.")
Reply
#2
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
False
Also, 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.")
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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?

>>> boy_names = ['Bob', 'Arthur', 'Kevin']
>>> 'Arthur' in boy_names
True
>>> 'Jane' in boy_names
False
Also, 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.")

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
Reply
#4
(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?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
(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 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!
Reply
#6
(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

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?

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble with threading and reading variable from a different script Lembas 14 2,841 Apr-26-2023, 11:21 PM
Last Post: Lembas
  Returning True or False vs. True or None trevorkavanaugh 6 9,113 Apr-04-2019, 08:42 AM
Last Post: DeaD_EyE
  setting pythonpath variable in environment variables saisankalpj 3 3,426 Dec-05-2018, 10:33 PM
Last Post: Gribouillis
  Having trouble defining variable tannishpage 6 5,564 Mar-23-2017, 01:04 PM
Last Post: Ofnuts
  How to turn variable true and false using function? hsunteik 5 6,421 Feb-20-2017, 11:44 AM
Last Post: hsunteik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020