我无法获得正确的多布尔运算结果

时间:2019-03-21 16:35:19

标签: boolean

我对编程很陌生,目前正在学习Python 3.X。

我将我学到的所有内容都放在文件中,同时尝试使其变得整洁和互动。

因此,我仅创建了一个有关布尔变量及其操作的文件,并编写了以下练习:


# Variables

sad = bool(input("Are you sad? "))

hungry = bool(input("Are you hungry? "))

tired = bool(input("Are you tired? "))

# Process

print("\nYou are sad, and hungry, and tired: ", sad and hungry and tired)

print("You are tired or hungry, but happy: ", (sad or hungry) and not sad)

print("You're not tired, or you're hungry or happy: ", not tired or hungry or not sad)

# Input:

sad = True 

hungry = False

tired = False

# Output:

You are sad, and hungry, and tired: True .......**should be False**

You are tired or hungry, but happy: False

You're not tired, or you're hungry, 

我试图在每对变量之间加上括号,但是得到的输出是相同的。发生了什么?我不应该这样做吗?

0 个答案:

没有答案