【发布时间】:2020-03-02 06:47:50
【问题描述】:
此作业的说明是:
我们传入 2 个布尔输入,寒冷和下雨。
你应该输出一个字符串:('cold' or 'warm') ' and ' ('rainy' 或“干”)基于这些输入。
('cold' or 'warm') 表示您应该使用这两个词中的一个,具体取决于 输入布尔值。
例如 False,True = '温暖多雨'
我放的代码是:
# Get our boolean values from the command line
import sys
isCold= sys.argv[1] == 'True'
isRainy= sys.argv[2] == 'True'
# Your code goes here
condition = ""
if (isCold):
condition += "cold"
else:
condition += "warm"
if (isRainy):
condition += " and rainy"
else:
condition += " and dry"
print(condition)
代码是正确的并输出它应该的,但我想知道有没有更简洁的方法来写这个?我觉得有,但我不太清楚。
【问题讨论】:
标签: python python-3.x if-statement conditional-statements boolean-expression