except KeyboardInterrupt
Since Ctrl-C causes KeyboardInterrupt to be raised, just catch it outside the loop and ignore it.
kinkun's blog
except KeyboardInterrupt
Since Ctrl-C causes KeyboardInterrupt to be raised, just catch it outside the loop and ignore it.
KyeboardからWhile LoopでEvent作成
def sample1(value):
    print(value)
try:
    while True:
        value = input()
        sample1(value)
except KeyboardInterrupt:
    pass結果
9
9
0
0Kyeboard入力とFunctionの使い方
def sample1(value):
    print(value)
value = input()
sample1(value)結果
9
9function呼び出し
def sample1(a, b, c):
    s = a + b - c
    print(a)
    if a == 0:
        print(b)
    else:
        print(c)
sample1(1, 1, 2)結果
1
2Pythonインストールと動作確認
・インストール
Windowsの場合、以下のURLにて、インストーラをダウンロードします。
https://www.python.org/downloads/windows/

・ダウンロードしたインストーラをPCにインストールします。
※インストール時、注意事項として、以下のように箇所にチェックいれて、「Install Now」押下します。

・インストール後に、PCの中に「test.py」ファイル作成して、その中に、以下のコードを入力して、保存します。
print("Hello world!")保存場所は、例えば、C:\Python\test.py
・Python Versionを確認します。
Windowsの場合、コマンドプロンプトを起動して、まずPythonを確認します。
C:\Users\p445-PC>python --version
Python 3.11.1・作成した、test.pyを実行します。
test.pyが保存されているDirectoryに移動します。
C:\>cd Pythontest.py実行します。
C:\Python>python test.py
Hello world!