如何为货币增值?

2024-05-01 21:52:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在python中增加货币的价值。我在用语言环境.货币创建格式,我把它放在一个变量中。我想打印要添加的变量+值以生成新值。你知道吗

import locale
locale.setlocale( locale.LC_ALL, '' )
'English_United States.1252'
while True:
    print("Welcome! Get ur pet here!")
    pet = input("Would you like a dog, cat, or fish:").lower()
    d = ("           __ \n      (___()'`;\n      /,    /` \n      \\\\'--\\\  ")
    money = (locale.currency( 25 ))
    if pet == "dog":
        print(money)  #I've done (money + 10) There is no error message, but 
                       #I want it to add 10 to 25 and it doesn't do that.
        print(d)

Tags: toimport语言环境格式货币itlocale
1条回答
网友
1楼 · 发布于 2024-05-01 21:52:37

local.curency返回一个字符串。你不能给它增加价值。你知道吗

您必须将货币存储为整数,并仅在打印时使用local.curency对其进行格式化。你知道吗

money = 25
if pet == "dog":
    print(locale.currency(money+10))
    print(d)

相关问题 更多 >