首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是什么导致了"TypeError:在字符串格式化过程中不是所有参数都被转换“

是什么导致了"TypeError:在字符串格式化过程中不是所有参数都被转换“
EN

Stack Overflow用户
提问于 2016-09-08 08:07:32
回答 1查看 21关注 0票数 0

这段代码会产生以下错误:

代码语言:javascript
复制
# -*- 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

错误:

代码语言:javascript
复制
<module>
  print("|Ø-6s|Ø-16s|Ø-9s|Ø-8s|Ø-14s|" % ("Month" , "Current Balance" , "Interest" , "Payment" , "Ending Balance"))
TypeError: not all arguments converted during string formatting
EN

回答 1

Stack Overflow用户

发布于 2016-09-08 08:13:19

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

代码语言:javascript
复制
print("|%-6s|%-16s|%-9s|%-8s|%-14s|" % ("Month" , "Current Balance" , "Interest" , "Payment" , "Ending Balance"))

代码语言:javascript
复制
print("|%-6f|%-16f|%-9f|%-8f|%-14f|" % (month , starting_balance , interest , monthly_rate , ending_balance))

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39380711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档