課程
/后端開發
/Python
/初識Python
這樣做對了嗎?
2016-09-22
源自:初識Python 5-3
正在回答
我覺得學習還是要掌握“編程的思想”的,雖然我還是菜鳥級別。
把題目用開閉區間表示:?[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'
按這個順序來寫不是更清晰有條理嗎?區間的劃定不會重合也不會遺漏。
手打不易望采納~
weibo_嘿不純粹_0
80在兩個條件中。
這個代碼有問題,首先可以嘗試80分就會顯示為“pass”。if的原理是從上到下執行,如果有匹配就不會再往下執行了。
舉報
學python入門視頻教程,讓你快速入門并能編寫簡單的Python程序
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-09-29
我覺得學習還是要掌握“編程的思想”的,雖然我還是菜鳥級別。
把題目用開閉區間表示:?[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'
按這個順序來寫不是更清晰有條理嗎?區間的劃定不會重合也不會遺漏。
手打不易望采納~
2016-09-22
80在兩個條件中。
2016-09-22
這個代碼有問題,首先可以嘗試80分就會顯示為“pass”。if的原理是從上到下執行,如果有匹配就不會再往下執行了。