KOTA ITO

Generation

generate functionMon, 19 Dec 2022

辞書に格納されたデータの0番目と1番目の要素を取り出す

def bmi(data): # 入力された辞書を変数dataとして定義 data = {'height': 2.0, 'weight': 80.5} # 辞書の中身を分解 for key, value in data.items(): print(key, value) # 辞書の0番目と1番目の要素を取り出す height = data['height'] weight = data['weight'] # BMIを計算 bmi_value = weight / (height ** 2) return bmi_value bmi(data)

Questions about programming?Chat with your personal AI assistant