我想为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)
答案 0 :(得分:1)
local.curency
返回一个字符串。您不能为其添加价值。
您必须将货币存储为整数,并仅在打印时用local.curency
对其进行格式化。
money = 25
if pet == "dog":
print(locale.currency(money+10))
print(d)