<分区> 分区>
这个作业的说明是:
We pass in 2 boolean inputs, cold and rainy.
You should output a single string: ('cold' or 'warm') ' and ' ('rainy' or 'dry') based on these inputs.
('cold' or 'warm') means you should use on of the two words, depending on the input boolean value.
for example False, True = 'warm and rainy'
我输入的代码是:
# 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)
代码是正确的并且输出了它应该输出的内容,但我想知道是否有更简洁的方式来编写它?我觉得有,但我不太明白。
