iT邦幫忙

1

python學生程式設計問題

  • 分享至 

  • xImage

https://ithelp.ithome.com.tw/upload/images/20220922/20153038dFTfxw8Unx.png該如何寫出程式解決這個問題?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

6
熊熊工程師
iT邦研究生 2 級 ‧ 2022-09-22 21:44:38
最佳解答

僅供參考

from datetime import datetime


def code_save_on_ithelp(data: str):
    birthday = datetime.strptime(data, "%Y%m%d")

    result = ""
    if 10 <= birthday.month <= 12:
        result += "科學麵"
    if birthday.day % 2 != 0:
        result += "飲料" if not result else "+飲料"
    if result == "":
        result = 0

    return result


if __name__ == '__main__':
    input_data = input("請輸入出生日期:")
    print(code_save_on_ithelp(data=input_data))

好好哦都有人幫忙寫作業

我要發表回答

立即登入回答