python

时间:2016-11-11 04:57:16

标签: python function

我写了以下代码:

def addInterest(balance, rate):
    newBalance = balance * (1+rate)
    return newBalance


def test():
    amount=1000
    rate=0.05
    addInterest(amount, rate)
    print("" ,amount)

test()

我预计输出为1050,但仍然打印1000.有人能告诉我我做错了什么吗?

2 个答案:

答案 0 :(得分:2)

您没有从AddInterest分配任何值:

amount = addInterest(amount, rate)

答案 1 :(得分:1)

函数addInterest()返回值1050,但不应用amount变量的更改,因为你没有作为引用变量传递(我认为python doenst支持引用的变量)。您必须将返回的值存储到新变量中:

UILocalNotification* localNotification = [[UILocalNotification alloc] init];

    localNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:100];

     localNotification.timeZone = [NSTimeZone defaultTimeZone];

    localNotification.soundName = UILocalNotificationDefaultSoundName;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];