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...
I would love it if anyone of you could help me out a bit :)
Thanks a lot in advance.
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...
Code:
import math
class Pension:
def __init__(self, name, age, amount):
self.name = name
self.age = age
self.amount = amount
def percentage():
p = float(raw_input('How many percent is the growth? '))
percentage = (p/100)+1
return percentage
def read():
f = open('file.txt','r')
rad = f.readline()
info = list()
while rad != '':
rad = rad.rstrip('\n')
parts = rad.split('/')
name = str(parts[0])
age = int(parts[1])
amount = float(parts[2])
temp = Pension(name,age,amount)
info.append(temp)
rad = f.readline()
f.close()
return info
def printing(info):
for i in range(len(info)):
print info[i]
percentage()
info = read()
printing(info)
Thanks a lot in advance.
Comment