假设price是一个整型变量,其值是以美分为单位的价格(以美元计)。写一份声明,将价格的价值以“X美元和Y美分”的形式单独打印在一行上。所以,如果price的值是4321,您的代码将打印“43美元21美分”。如果值是501,它将打印“5美元1美分”。如果值为99,则代码将打印“0美元99美分”。在
我是这样做的:
print (price/100,"dollars and",price%100, "cents")
结果示例:2314
^{pr2}$
如何使结果看起来像:
23 dollars and 14 cents
Tags:
输入:
输出:
^{pr2}$您可以使用:
这将输出:
^{pr2}$操作是正确的;在python3中+两者都是
以及
^{pr2}$给出期望的结果。在
下面是一个包含测试策略的直接字符串处理攻击:
相关问题 更多 >
编程相关推荐