造成什么原因" TypeError:并非在字符串格式化期间转换所有参数"

时间:2016-09-08 00:07:32

标签: python

此代码产生错误:

'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',

错误:

# -*- coding: utf-8 -*-
amount = float(input("Enter the purchase price please."))
down_payment=amount *0.10
monthly_rate = (amount - down_payment) *.05

ending_balance=amount-down_payment

print("|Ø-6s|Ø-16s|Ø-9s|Ø-8s|Ø-14s|" % ("Month" , "Current Balance" , "Interest" , "Payment" , "Ending Balance"))
month = 1
while True:
    starting_balance = ending_balance
    interest = starting_balance * 0.01
    final_amount = (starting_balance+interest)

    if monthly_rate > final_amount:
          monthly_rate = final_amount


    ending_balance = final_amount - monthly_rate

    print("|Ø-6f|Ø-16f|Ø-9f|Ø-8f|Ø-14f|" % (month , starting_balance , interest , monthly_rate , ending_balance))
    month+=1

    if ending_balance <= 0:
      break

1 个答案:

答案 0 :(得分:0)

您必须在格式化字符串中使用%而不是Ø

print("|%-6s|%-16s|%-9s|%-8s|%-14s|" % ("Month" , "Current Balance" , "Interest" , "Payment" , "Ending Balance"))

print("|%-6f|%-16f|%-9f|%-8f|%-14f|" % (month , starting_balance , interest , monthly_rate , ending_balance))

请参阅:https://pyformat.info/