#38360: python也可以兩行解


yucoh1013@gmail.com (帥哥)

學校 : 高雄市立高級商業職業學校
編號 : 243623
來源 : [163.32.95.106]
最後登入時間 :
2024-05-01 12:41:17
h291. 月份名稱 | From: [114.39.86.82] | 發表日期 : 2023-11-14 22:26

題目有給一長串'January, February, March, April, May, June, July, August, September, October, November, December'

有這個就可以用字串分割.split(', ')存成list

就可以利用index 不需要在那邊用if elif ...

 

data = 'January, February, March, April, May, June, July, August, September, October, November, December'.split(', ')
print(data[int(input()) - 1])

 
#38361: Re: python也可以兩行解


yucoh1013@gmail.com (帥哥)

學校 : 高雄市立高級商業職業學校
編號 : 243623
來源 : [163.32.95.106]
最後登入時間 :
2024-05-01 12:41:17
h291. 月份名稱 | From: [114.39.86.82] | 發表日期 : 2023-11-14 22:28

題目有給一長串'January, February, March, April, May, June, July, August, September, October, November, December'

有這個就可以用字串分割.split(', ')存成list

就可以利用index 不需要在那邊用if elif ...

 

data = 'January, February, March, April, May, June, July, August, September, October, November, December'.split(', ')
print(data[int(input()) - 1])


更 其實可以一行解

print('January, February, March, April, May, June, July, August, September, October, November, December'.split(', ')[int(input()) - 1])
 
ZeroJudge Forum