LoginSignup
1
0

ChatGPで月の満ち欠けプログラム

Posted at

ChatGPTを使ったプログラム作成にチャレンジ

 ChatGPT4に

年月日より、月の満ち欠けを表示するプログラムコードは?

と尋ねたところ1回のエラーだけで作り上げてきました。
 恐るべし。

moon_age.py
import ephem

def get_moon_phase(year, month, day):
    date = ephem.Date(f"{year}/{month}/{day}")
    moon = ephem.Moon(date)
    age = ephem.previous_new_moon(date) - ephem.previous_new_moon(moon.previous_new())

    if age < 1.0:
        phase = "New moon"
    elif age < 7.4:
        phase = "First quarter - Waxing crescent"
    elif age < 14.8:
        phase = "Full moon"
    elif age < 22.1:
        phase = "Last quarter - Waning gibbous"
    else:
        phase = "New moon"
    
    return phase

year = 2023
month = 7
day = 3
print(get_moon_phase(year, month, day))

こんな感じでした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0