Py学习  »  Python

Python中if语句的问题

Rory Green • 3 年前 • 1346 次点击  

我是一名新的python用户,一直在尝试将用户输入集成到一个更简单的代码中。原始代码如下所示。

起初的 ============================ ============== ============== ==============

is_male=True
is_tall=False
if is_male and is_tall:
    print("User is male and tall.")
elif is_male and not(is_tall):
    print("User is male and short.")
elif not(is_male) and is_male:
    print("User is female and tall.")
else:
    print("User is female and short")

这是我想要的方式,但我希望用户能够输入这些信息。然而,我遇到了一个问题,控制台上总是写着“用户是男性且身材高大”我下面的新代码有什么问题?非常感谢你。

修改

is_male=input("You are male. True or False?")
if is_male == "True": 
    is_male == True
elif is_male == "False":
    is_male == False
else:
    print("Please enter True or False.")

is_tall=input("You are tall. True or False?")
if is_tall == "True": 
    is_tall == True
elif is_tall == "False":
    is_tall == False
else:
    print("Please enter True or False.")

is_male=True
is_tall=False
if is_male and is_tall:
    print("User is male and tall.")
elif is_male and not(is_tall):
    print("User is male and short.")
elif not(is_male) and is_male:
    print("User is female and tall.")
else:
    print("User is female and short")
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129345
 
1346 次点击  
文章 [ 2 ]  |  最新文章 3 年前