ソースコード
# coding:utf-8
# 分岐文
import os
os.system("clear")
sum=0
work=True
while work == True:
# 買い物の消費税の種類を選んで貰う
print("\n\nーーー食料品の購入ーーー")
flag = True
choice = input("1 : 食料品 2 : それ以外" )
if choice in ['1','1'] :
tax_rate =0.08
elif choice in ['2', '2'] :
tax_rate = 0.1
else :
print("入力ミス")
flag= False
# 買い物の値段計算
if flag== True :
product_name =input("品名を入れて: ")
apple_price = int(input("単価: "))
qty = float(input("数量: "))
total_price =round( (1 + tax_rate) * apple_price * qty)
sum += total_price
print(f"{product_name} 合計{total_price:.0f} 円\n 単価 {apple_price}円 消費税 {tax_rate} 購入個数 {qty}")
ask = input("買物を続きますか?\n\n続くならENTERを 辞めるならならN/n を入れて:")
if ask in ["N","n"]:
work=False
print(f'\n 総額は{sum: .0f}円です。')