如何为货币增值?

时间:2019-06-24 19:56:28

标签: python python-3.x

我想为python中的货币增加价值。我正在使用locale.currency创建格式,并且将其包含在变量中。我要打印要添加的变量+值以创建新值。

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)

1 个答案:

答案 0 :(得分:1)

local.curency返回一个字符串。您不能为其添加价值

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

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