这样做对了吗?
这样做对了吗?
我觉得学习还是要掌握“编程的思想”的,虽然我还是菜鸟级别。
把题目用开闭区间表示: [90,+∞) : excellent, [80,90) : good, [60,80) : passed, (-∞ ,60):failed, 那么按顺序来呗:
if score >= 90:
print 'excellent'
elif score >= 80:
print 'good'
elif score >= 60:
print 'passed'
else:
print 'failed'
如果题目这样出: (-∞ ,60):failed, [60,80) : passed, [80,90) : good, [90,+∞) : excellent, 那么可以这样写:
if score < 60:
print 'failed'
elif socre <80:
print 'passed'
elif socre <90:
print 'good'
else:
print 'excellent'
按这个顺序来写不是更清晰有条理吗?区间的划定不会重合也不会遗漏。
手打不易望采纳~
举报