0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

自作アプリ No.5 (1個)

Posted at

以前作っていたホームページを一度作り直すので、
そのホームページに書いていたコードをこっちに残しときます。

No.5 Hello Worldを表示するファイルを作成するプログラム


# coding:utf-8
# No.5
# hello worldを表示するファイルを作成するプログラム
 
def main():
    print('以下の文を書いてください')
    saisyo = input('#coding: utf-8 と書いてね')
    hello = input('print("Hello World") と書いてね')
    name = input("最後にこのファイルの名前を決めてね")

    # "/n"を使うことで改行
    kekka = saisyo+"\n"+hello

    print(kekka)

    # .pyは拡張子を決定し、wというのは書き込みモード
    file = open(name+'.py','w')

    # ファイルにkekkaに代入されている文字列を書き込む処理
    file.write(kekka)
    file.close()
    print('Hello Worldと表示されるプログラムがこのファイルを実行した場所に作成されたよ!')

main()

# なんで関数を作ったのかは覚えていません・・・w

※番外編

このファイルと同じフォルダに鳴らしたい音源が存在することが前提となってます。
番外編と書いたのは音を鳴らしたい時どうすればいいか調べていた時に参考になるコードを見つけ、それを参考にしたからです。音を鳴らす部分のコードはほぼコピペの為自作じゃないからですw

# coding: utf-8

# x秒後に音をならして教えてくれるプログラム

import time
import wave
import pyaudio
 
print("設定したら音を鳴らして教えてくれるよ!")
time.sleep(2)
ongen = input("まずは鳴らしたい音源ファイルを入力してね!例:doremi.wav")
sec = input("何秒後にお知らせしますか?")
print("OK!時間が来た教えるねー!")
time.sleep(int(sec))
print("時間だよー!")
    
if __name__ == '__main__':
   
    wf = wave.open(ongen, "r")
    # ストリームを開く
    p = pyaudio.PyAudio()
    stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                    channels=wf.getnchannels(),
                    rate=wf.getframerate(),
                    output=True)
    # チャンク単位でストリームに出力し音声を再生
    chunk = 1024
    data = wf.readframes(chunk)
    while data != '':
        stream.write(data)
        data = wf.readframes(chunk)
    stream.close()
    p.terminate()
 time.sleep(1)
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?