LoginSignup
1
0

More than 1 year has passed since last update.

閏年か否かを求めるコード

Last updated at Posted at 2022-09-18

閏年か否かを求めるコード

閏年.py
import tkinter as tk

def dispLabel():
    a = int(EditBox.get())
    str_a=str(a)

    if a%400 == 0 :
        lbl3.configure(text = str_a + "年は閏年です。")

    elif a%100 == 0 :
        lbl3.configure(text = str_a + "年は閏年ではありません。")

    elif a%4 == 0 :
        lbl3.configure(text = str_a + "年は閏年です。")

    else :
        lbl3.configure(text = str_a + "年は閏年ではありません。")
    
root = tk.Tk()
root.geometry("300x200")

EditBox = tk.Entry(width=6)
EditBox.place(x = 230, y = 20)

btn = tk.Button(text = "調べる", command = dispLabel).place(x = 60, y = 50)

lbl1 = tk.Label(text = "調べたい年は何年ですか?").place(x = 20, y = 20)
lbl2 = tk.Label(text = "").place(x = 260, y = 20)
lbl3 = tk.Label(text = " ")
lbl3.place(x = 20, y = 100)



tk.mainloop()

感想

  • どのような順で割り算を行ったら、閏年か否かを判別できるかを考えるのに頭を悩ませた。
1
0
1

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