440,097 Members | 1,529 Online
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

# How to create a pension calculator?

4 Replies

 Expert 100+ P: 621 This is the code I have so far and im kind of stuck now on how to get it working. I would love it if anyone of you could help me out a bit What does this mean? One obvious flaw is that "info" is a list of classes so you would print the fields of the class. An example follows. See "Defining Classes" here for basic class info. Note that you are doing the same thing as is done in "Using Classes" except you are doing this within a loop. Expand|Select|Wrap|Line Numbers def printing(info):     for class_instance in info:         print class_instance.name, class_instance.age, \               class_instance.amount ## ##   you could also add a print method to the class  ## class Pension:       def __init__(self, name, age, amount):         self.name = name         self.age = age         self.amount = amount       def print_data(self):         print self.name, self.age, self.amount   def printing(info):     for class_instance in info:         class_instance.print_data()  Nov 3 '10 #2

 P: n/a That's great! Thank you very very much. :D Now the only thing I have left is adding the formula with the percentage and then print the finished list, which should include the name and how much they would have once they reach the age of 65. Nov 4 '10 #3

 P: n/a Is there a way to use the sum() function in order to calculate this? Or is there an integral function already in python or possible in the math module? SUM OF[ amount*math.pow(percentage, yearsLeft-1) + amount*math.pow(percentage, yearsLeft-2) + amount*math.pow(percentage, yearsLeft-3) + ... + amount*math.pow(percentage, yearsLeft-yearsLeft) ] Nov 5 '10 #4

 P: n/a what I meant was: (amount*math.pow(percentage, yearsLeft-n)) where n goes from 0 to yearsLeft Nov 5 '10 #5