LoginSignup
1
3

More than 3 years have passed since last update.

キッチンタイマープログラム 完成版

Posted at

キッチンタイマープログラム

以前、初投稿時に作成したキッチンタイマープログラム。未完成品ではあったもののアドバイスを基に改善することができました。

プログラムコード

授業課題で提出予定のプログラムです。


from time import sleep
import time
import pygame.mixer

minute_to_second=60

def alert():
    print("時間です")
    Sound()
    exit()

def Sound():
    pygame.mixer.init()
    pygame.mixer.music.load("Onmtp-Ding04-2.mp3")
    pygame.mixer.music.play(-1)
    input()
    pygame.mixer.music.stop()

while True:
    print("タイマーを設定する時間を指定してください")
    min=input("何分に設定するか選択してください。(minかsecがqで終了):")
    sec=input("何秒に設定するか選択してください。(minかsecがqで終了):")
    if min=="q" or sec=="q":
        print("設定を中断しました。")
        break

    try:
        minute=int(min)
        if 0<=minute<=99:
            wait_time1=(minute*minute_to_second)
        else:
            if 0>minute or 99<minute:
                print("minで入力できる数字は0から99までです。")
                continue
    except ValueError:
        print("数字以外は入力しないでください。")

    else:
        try:
            second=int(sec)
            if 0<=second<=59:
                wait_time2=wait_time1+second
                print(min+"分"+sec+"秒にタイマーをセットしました。")
                sleep(wait_time2)
                alert()
            else:
                if 0>second or 59<second:
                    print("secで入力できる数字は0から59までです。")
                    continue
        except ValueError:
            print("数字以外は入力しないでください。")

感想

これを口頭で説明するのって難しいですよね、、、。
でも、自力で50行程度のコードを書いたことは無かったので少しずつ成長が実感できますね!

1
3
3

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
3