Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

python - I'm trying to make a simple story maker but I'm stuck on the gender part

Im trying to make a simple story that contains users input, but i can't get my gender part to work. I want it to be able to recognize the gender from the input and then print the appropriate pronoun.

import time
print("What's your name?")
character_name = input("Type it in here: ")
print("How old are you?")
character_age = input("Type your age in here here: ")
def isMale():
    Male = input("You're a male? True or False?")
    if (Male == "True"):
        Male_Bool = True
    elif (Male == "False"):
        Male_Bool = False
    if (Male_Bool) == True:
        print("There was a man named " + character_name + ", ")
        print("he was " + character_age + ".")
        print("He likes the name " + character_name + ", ")
        print("but didn't like being " + character_age + ".")
    elif(not Male_Bool) == False:
        print("There was a woman named " + character_name + ", ")
        print("she was " + character_age + ".")
        print("She likes the name " + character_name + ", ")
        print("but didn't like being " + character_age + ".")
    return isMale()
time.sleep(10)
question from:https://stackoverflow.com/questions/65938098/im-trying-to-make-a-simple-story-maker-but-im-stuck-on-the-gender-part

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think it is something like this that you are looking for.

import time
print("What's your name?")
character_name = input("Type it in here: ")
print("How old are you?")
character_age = input("Type your age in here here: ")
def isMale():
    Male = input("You're a male? True or False?")
    if (Male == "True"):
        Male_Bool = True
    elif (Male == "False"):
        Male_Bool = False
    if (Male_Bool) == True:
        print("There was a man named " + character_name + ", ")
        print("he was " + character_age + ".")
        print("He likes the name " + character_name + ", ")
        print("but didn't like being " + character_age + ".")
    #Check if Male_Bool is False
    elif(Male_Bool) == False:
        print("There was a woman named " + character_name + ", ")
        print("she was " + character_age + ".")
        print("She likes the name " + character_name + ", ")
        print("but didn't like being " + character_age + ".")
    return 
#Call the function
isMale()
time.sleep(10)

Also have a look at your code restructured.

import time

def isMale():
    Male = input("You're a male? True or False?")
    if (Male == "True"):
        Male_bool = True
    else:
        Male_bool = False
    return Male_bool

character_name = input("What's your name?")
character_age = input("How old are you?")
male = isMale()
if male:
    print(f"There was a man named {character_name},")
    print(f"he was {character_age}.")
    print(f"He likes the name {character_name},")
    print(f"but didn't like being {character_age}.")
else:
    print(f"There was a woman named {character_name},")
    print(f"she was {character_age}.")
    print(f"She likes the name {character_name},")
    print(f"but didn't like being {character_age}.")

time.sleep(10)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...