如果要同時輸入多個數據呢?怎么辦?
age=20
if age >= 18:
? ? ? ? ? print 'adult'else:
?if age >= 6:
? ? ? ? ?print 'teenager' ? ?else:
? ? if age >= 3:
? ? ? ? ? print 'kid' ? ? ? ?else:
? ? ? ? ? print 'baby'如果還有個age=17難道要重新寫過一遍嗎?有沒有什么簡便的方法?
age=20
if age >= 18:
? ? ? ? ? print 'adult'else:
?if age >= 6:
? ? ? ? ?print 'teenager' ? ?else:
? ? if age >= 3:
? ? ? ? ? print 'kid' ? ? ? ?else:
? ? ? ? ? print 'baby'如果還有個age=17難道要重新寫過一遍嗎?有沒有什么簡便的方法?
2017-11-05
舉報
2017-11-05
for age in [20,17]:
? ?if age >= 18:
? ? ? ? ?print 'adult'
? ?elif age >= 6:
? ? ? ? print 'teenager'
? ?elif age >= 3:
? ? ? ? ?print 'kid'
? ?else: print 'baby'
放在列表里循環就可以了