473,465 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to create a pension calculator?

Hi guys,
Im using windows 7 and python 2.7.

I need to read in info from a file in the format:
name/age/amount
for example: johan/20/1000

Then for example if you have 1000$ and the growth 5% for 20 years it would be 1000*1.05^20.

The only thing that isnt read from the file is the interest which is read from a raw_input.

This is the code I have so far and im kind of stuck now on how to get it working. I am not very good with classes and objects...

Expand|Select|Wrap|Line Numbers
  1. import math
  2.  
  3. class Pension:
  4.  
  5.     def __init__(self, name, age, amount):
  6.         self.name = name
  7.         self.age = age
  8.         self.amount = amount
  9.  
  10.  
  11. def percentage():
  12.     p = float(raw_input('How many percent is the growth? '))
  13.     percentage = (p/100)+1
  14.     return percentage
  15.  
  16.  
  17. def read():
  18.     f = open('file.txt','r')
  19.     rad = f.readline()
  20.     info = list()
  21.     while rad != '':
  22.         rad = rad.rstrip('\n')
  23.         parts = rad.split('/')
  24.         name = str(parts[0])
  25.         age = int(parts[1])
  26.         amount = float(parts[2])
  27.         temp = Pension(name,age,amount)
  28.         info.append(temp)
  29.         rad = f.readline()
  30.     f.close()
  31.     return info
  32.  
  33.  
  34. def printing(info):
  35.     for i in range(len(info)):
  36.         print info[i]
  37.  
  38.  
  39.  
  40. percentage()
  41. info = read()
  42. printing(info)
  43.  
  44.  
I would love it if anyone of you could help me out a bit :)
Thanks a lot in advance.
Nov 3 '10 #1
4 3552
dwblas
626 Recognized Expert Contributor
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
  1. def printing(info):
  2.     for class_instance in info:
  3.         print class_instance.name, class_instance.age, \
  4.               class_instance.amount
  5. ##
  6. ##   you could also add a print method to the class 
  7. ##
  8. class Pension:
  9.  
  10.     def __init__(self, name, age, amount):
  11.         self.name = name
  12.         self.age = age
  13.         self.amount = amount
  14.  
  15.     def print_data(self):
  16.         print self.name, self.age, self.amount
  17.  
  18. def printing(info):
  19.     for class_instance in info:
  20.         class_instance.print_data() 
Nov 3 '10 #2
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
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
what I meant was:
(amount*math.pow(percentage, yearsLeft-n)) where n goes from 0 to yearsLeft
Nov 5 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marcus | last post by:
I have a question. I am currently responsible for updating the entire payroll and pensioner system for several pension funds. I have made the appropriate tables for demographics, home address,...
1
by: remya1000 | last post by:
from my system i need to open a calculator in remote machine. and i'm using Vb.net and WMI. i need to pop up the calculator in remote machine, while i run one program in my system. while running in...
2
by: jtanz0 | last post by:
Im fairly new to java programming although i have some experience in python. I have to create a calculator program (command line) which takes as input a mathematical expression consisting of...
17
by: Max347 | last post by:
This is my first post, so hopefully I can give enough information. I am running windows xp, using jGrasp to write code. I need to make a calculator in which the user inputs 2 floating point numbers...
1
by: yamyliz | last post by:
Well I dont know if this is of any help but here it goes: I put a text box (Text3) and 16 command buttons. For each commandbutton I entered a code, like this: 1 --> Text3 = "1" 2 --> Text3...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
8
by: jac130 | last post by:
I need to create a calculator using combo boxes/procedures/functions etc... and some other stuff. most of it works properly, but, i need to create a user defined function that checks if both input...
7
risk32
by: risk32 | last post by:
Hi all, I'm still in the beginning stages of JS, so I really don't know how to do this. I'm trying to create a calculator, which I did, but I couldn't get the % to work. I thought maybe I could...
3
by: Chimok | last post by:
I create a calculator in visual basic and I put button from 0 to 9 ... and event click textbox1.text = textbox1 + "1" (to 9) ..it work good .. but if i press key 0 from keybord nothing is hapens...
2
momotaro
by: momotaro | last post by:
Hi, Am trying to creat a calculator using vb.net and can't figure out what component is used to display for the windows 7 calculator thank's in advance
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.