alexa-tracking

Main Content

1024
1024
KASKUS
51
244
https://www.kaskus.co.id/thread/52debd615ccb17ea57000379/net-present-value-calculator-created-in-python-27
Net Present Value calculator created in Python 2.7
Selamat malem agan2,

Ane baru belajar Python 2.7 nih, alhamdulillah berhasil bikin program sederhana menghitung Net Present Value. Nah ane posting disini tujuannya buat sharing n biar ada saran/tanggapan/kritikan pedas dari agan2 disini.

Spoiler for Kode program:


Gimana agan2? berani berkomentar? emoticon-Big Grin
Quote:Original Posted By oxylane
Selamat malem agan2,

Ane baru belajar Python 2.7 nih, alhamdulillah berhasil bikin program sederhana menghitung Net Present Value. Nah ane posting disini tujuannya buat sharing n biar ada saran/tanggapan/kritikan pedas dari agan2 disini.

Spoiler for Kode program:


Gimana agan2? berani berkomentar? emoticon-Big Grin

codenya ga "pythonic" lebih mirip kode C/C++/Java yang ditulis dalam bahasa python

not tested sama sekali, cuma ubah2 dari kode yang lu kasih

Code:

def npv():
investment = int(raw_input("Investment = "))
interest = float(raw_input("Interest = "))
year = int(raw_input("Year = "))

cashflow = [int(raw_input("Cashflow year %d = " % (i + 1))) for i in year]

pv = [cashflow[i] / ((1 + interest) ** i) for i in year]
hasil = sum(pv) - investment
print "NPV = %s\n" % hasil
if (hasil < 0):
print "Because NPV < 0, it would be better if investment to be cancelled"
else:
print "Because NPV > 0, it would be better if we doing this investment"

npv()
Nice gan emoticon-Big Grin ,,,,

sesegera mungkin migrasi ke python 3 ....tpi waspada syntak na bnyak yg beda emoticon-Ngakak

Quote:Original Posted By marcadian

codenya ga "pythonic" lebih mirip kode C/C++/Java yang ditulis dalam bahasa python

not tested sama sekali, cuma ubah2 dari kode yang lu kasih

Code:

def npv():
investment = int(raw_input("Investment = "))
interest = float(raw_input("Interest = "))
year = int(raw_input("Year = "))

cashflow = [int(raw_input("Cashflow year %d = " % (i + 1))) for i in year]

pv = [cashflow[i] / ((1 + interest) ** i) for i in year]
hasil = sum(pv) - investment
print "NPV = %s\n" % hasil
if (hasil < 0):
print "Because NPV < 0, it would be better if investment to be cancelled"
else:
print "Because NPV > 0, it would be better if we doing this investment"

npv()


hahaha ane emang basicnya C++/Java gan
makasih masukan + koreksinya emoticon-Blue Guy Cendol (L)
Quote:Original Posted By badycool2
Nice gan emoticon-Big Grin ,,,,

sesegera mungkin migrasi ke python 3 ....tpi waspada syntak na bnyak yg beda emoticon-Ngakak



lho python 2 udah ga disupport lagi atau gimana gan?
saran aja ya gan.. emoticon-Malu (S) oop nya itu.. prinsip oop "single responsibility principle" nya juga belum dapet ... i object ( class or function) idealnya seh hanya memegang satu kewajiban aja.. emoticon-Ngakak (S) dari pada di buat function supermen kaya gitu... emoticon-Malu (S)
Quote:Original Posted By 0neD
saran aja ya gan.. emoticon-Malu (S) oop nya itu.. prinsip oop "single responsibility principle" nya juga belum dapet ... i object ( class or function) idealnya seh hanya memegang satu kewajiban aja.. emoticon-Ngakak (S) dari pada di buat function supermen kaya gitu... emoticon-Malu (S)


wah ane masih belum nyampe OOPnya, tapi makasih udah merespon emoticon-Blue Guy Cendol (L)
Ane bikin aplikasi jadinya siap pakai tinggal install saja.. barangkali bis klik http://kask.us/h8wsA

Net Present Value calculator created in Python 2.7