我是一个非常非常初学的程序员,为了好玩而做一些简单的数据分析。自从我用Python做了一些事情已经有几个月了,所以我确信它很笨重而且不优雅,如果有大问题我也不会感到惊讶。
这是给我带来麻烦的功能:
def growth (city, percentage):
neww = int(city + city * percentage)
return neww
然后代码的其余部分:
def printStyle (cityName, cityString):
print cityName+": "+str(cityString)
newYork=19831858
losAngeles=13052921
chicago=9522434
y=2012
while y<2020:
newYork = growth(newYork, 0.0135)
losAngeles = growth(losAngeles, 0.0175)
chicago = growth(chicago, 0,0065)
print "Year: "+str(y)
printStyle ("New York", newYork)
printStyle ("Los Angeles", losAngeles)
printStyle ("Chicago", chicago)
这是错误:
Traceback (most recent call last):
File "<stdin>", line 49, in <module>
TypeError: growth() takes exactly 3 arguments (2 given)
我正在使用Python 2.7。你觉得怎么样?
答案 0 :(得分:3)
删除此行中,
之后的0
:
chicago = growth(chicago, 0.0065)
答案 1 :(得分:2)
chicago = growth(chicago, 0,0065)
那里有一个逗号作为小数点分隔符。