【发布时间】:2013-04-19 03:52:27
【问题描述】:
对不起,如果我只是愚蠢,但我是 python 新手。当我执行此操作并输入一个大于 7 的数字时,它会给出 5、6 和 7 的答案,并打印 > 7。它告诉我,“我希望它越过边界变成真棒”,然后是“太棒了”。 PS我正在使用Python 3
print ('What is your name?')
LeName = input ()
print (' How are you, ' + LeName + '?')
print ('On a scale of one to ten, what would you rate your day so far?')
mood = int (input())
if mood <4:
print ('That\'s horrible, I hope it gets better.')
if mood == '5' '6' or '7':
print('Hope it crosses the border into awesome! :)')
if mood > 7:
print('That\'s awesome!')
print ()
发帖后大约 1/2 小时,我考虑了一下,将 if mood == '5' '6' of '7' 更改为 if mood >= and mood
【问题讨论】:
-
@MattBall -- 令人惊讶的是,它是有效的,但是“这甚至不是有效的代码!”也是我的第一个直觉。
-
附带说明,您可以使用不同类型的引号来避免所有那些丑陋的转义序列:例如
print("That's awesome!") -
还可以考虑使用 elif 语句代替后续的 if。通常,它们是防止多次匹配的有用方法。
标签: python python-3.x