前提・実現したいこと
閲覧ありがとうございますm(_ _)m
プログラミングは全くの初心者で、本を読みながらpythonの勉強をしているのですが、本の通りにコーディングしたはずなのにエラー(can't multiply sequence by non-int of type 'float')が出てしまいました。
chap461.pyの9行目・・・変数billを指定してモジュール(chap4func)のadd_charge関数を呼び出したい
10行目・・・変数recのキー(name)と変数billを指定してモジュール(chap4func)のcreate_mail関数を呼び出したい
回答宜しくお願いします。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "/Users/anonymous/Documents/chap461.py", line 9, in <module> bill=chap4func.add_charge(bill) File "/Users/anonymous/Documents/chap4func.py", line 10, in add_charge return int (bill*1.07) TypeError: can't multiply sequence by non-int of type 'float'
該当のソースコード
chap4func.py def create_mail(recv,bill): tmp='''Mr.{} im Saito i need {} yen ''' msg=tmp.format(recv,bill) print(msg) def add_charge(bill): return int (bill*1.07)
chap461.py import chap4func data=[ {'name':'yamamoto','bill':'40000','crg':True}, {'name':'takahashi','bill':'25000','crg':False} ] for rec in data: bill=rec['bill'] if rec['crg']: bill=chap4func.add_charge(bill) chap4func.create_mail( rec['name'],bill)
回答2件
あなたの回答
tips
プレビュー