如何循环我的代码以使其以递增的方式上升?

时间:2016-06-05 01:59:49

标签: python-3.x

我希望每次循环时我的代码都会以增量递增,但我不确定该怎么做。如何让它重复自己,同时增加10倍,10倍。

这是我到目前为止所做的:

def money():
amount = float(input("Enter NZ convertion amount:$ "))
AUD = amount*0.96
US = amount*0.75
Euro = amount*0.67
GBP = amount*0.496
print('NZ$', amount,'AUD: {}, US:{}, Euro: {}, GBP: {}'.format(AUD, US, Euro, GBP))
return
money()

任何想法?

2 个答案:

答案 0 :(得分:1)

AUD = 0.96
US = 0.75
EUR = 0.67
GBP = 0.496

def money(delta, times):
    amount = float(input("Enter NZ convertion amount:$ "))

    for dta in range(times):
        amt = amount + delta * dta 
        print('NZ$ {} AUD: {}, US:{}, Euro: {}, GBP: {}'.format(amt,
                                                                amt * AUD,
                                                                amt * US,
                                                                amt * EUR,
                                                                amt * GBP)

money(10.0, 10)

答案 1 :(得分:0)

为什么不简单地将计算和打印部分包装成10次for循环?

tag_str += ' '

tag_str += tag