python b
          
                

モジュール作成例題

#モジュール作成例題: 税込金額計算モジュール tax.py 2022/11/4 N.SUN #coding:utf-8 import os #関数定義 def getprice(): x = int(input("単価いくらですか? ")) y = int(input("何個ですか? : ")) return x*y def gettax(): kind = '3' while kind not in ['1','2']: print('食料品なら1を、食料品以外は2を',end=' ') kind = input("入力してください: ") if kind not in ['1','2']: print("入力ミス。もう一度入力しください。 ") return kind def caltax(kind, price): word = ["食料品 ","食料品以外 "] choice = word[int(kind)-1] if kind == '1': ans = round(price*1.08) print(choice + "の消費税は8%、税込金額は "+str(ans)+"となります。\n ") elif kind=='2': ans = round(price*1.1) print(choice + "の消費税は10%、税込金額は "+str(ans)+"となります。\n ") return ans def mytax(): sum = 0 while True: os.system('clear') print("\t\t\t 税込金額計算\n------------------------------------------------------------------- ") kind = gettax() price = getprice() answer = caltax(kind,price) sum += answer y = input("計算を続けてしたいなら1を、やめたいならEnterキーを押してください: ") print("合計=",sum)

...

#税込金額計算 #coding:utf-8 import tax print("\nご利用ありがとうございました。\n") tax.mytax()
実行結果