我的代码运行得很完美,并且得到了我想要的结果。然而,最后一次打印(“焦虑:")并不是输出焦虑,而是只打印出没有标题的答案。
我已经在空闲3.10.1以及我的Python类自己的Python程序中多次运行这个程序,并且得到了完全相同的结果。绝对没有错误,但在最后一次打印语句之后也没有标题。
有人知道发生了什么事吗?我以前的代码中没有遇到过这样的问题,我是为我的在线课程而运行的。
谢谢!
busy = True
hungry = False
tired = True
stressed = False
happy = busy and not stressed
sad = hungry or tired
print("Happy: " + str(happy))
print("Sad: " + str(sad))
print("Confused: "+ str(happy and sad))
print("Bored: " + str(not(happy or sad or busy)))
print("Anxious: " + str(not happy) and (not sad) and (not stressed))发布于 2022-01-27 13:25:19
这只是一个逻辑错误:
busy = True
hungry = False
tired = True
stressed = False
happy = busy and not stressed
sad = hungry or tired
print("Happy: " + str(happy))
print("Sad: " + str(sad))
print("Confused: "+ str(happy and sad))
print("Bored: " + str(not(happy or sad or busy)))
print("Anxious: " + str(not happy and (not sad) and (not stressed)))这是:
print("Anxious: " + str(not happy) and (not sad) and (not stressed)))应:
print("Anxious: " + str(not happy and (not sad) and (not stressed)))
#or
print("Anxious: " + str((not happy) and (not sad) and (not stressed)))发布于 2022-01-27 13:25:23
线
print("Anxious: " + str(not happy) and (not sad) and (not stressed))
评估为
print("Anxious: False" and False and True)
字符串总是计算为True,所以您要打印True and False and True的结果,它只是打印False。
发布于 2022-01-27 13:26:27
它不起作用,因为对str的偏执不包括整个操作--它只是覆盖操作的not happy部分,因此,您所要做的就是给它添加一个新的偏执。
print("Anxious: " + str((not happy) and (not sad) and (not stressed)))https://stackoverflow.com/questions/70879246
复制相似问题