したがって、ユーザーが毎月どれくらいの金額を費やしているかを計算し、その数値を使って年間の費用を計算する必要があります。私は彼らの年間経費を取得するために12で自分の毎月の費用を掛けてみたかったが、私は「*」私はオペレータとのint型と機能を掛けることはできません同じエラーで関数に整数を掛ける方法は?
def loan_payment():
loan = float(input("Please enter how much you expend monthly on loan payments:"))
return loan
def insurance_cost():
insurance = float(input("Please enter how much you expend monthly on insurance:"))
return insurance
def gas_cost():
gas = float(input("Please enter how much you expend monthly on gas:"))
return gas
def maitanence_cost():
maitanence = float(input("Please enter how much you expend monthly on maintanence:"))
return maitanence
def monthly_cost():
monthly_expenses = float(loan + insurance + gas + maintanence)
return float(monthly_expenses)
print("You expend $"+format(monthly_cost, '.2f')+"in a month.")
def yearly_cost():
yearly_expenses = 12 * monthly_cost
return yearly_expenses
print("At your current monthly expenses, in a year you will have paid $"+format(yearly_cost, '.2f')+".")
def main():
loan_payment()
insurance_cost()
gas_cost()
maitanence_cost()
monthly_cost
yearly_cost()
main()
は '12 * monthly_cost'を' 12 * monthly_cost() 'にする必要がありますか? – castis
関数を整数で乗算しません。関数呼び出しの結果に整数を掛けることもできます。 – miradulo