%[player_bank]d
Please help me out, thank you.
Code: Select all
python:
interest_rate = 0.01
n = 5 # number of intervals
player_bank = player_bank * pow(1+interest_rate,n)
player_bank = int(player_bank) # if you need only $ without cents
Code: Select all
label banktest:
$ day = 1
"I think I'll open a bank account."
"Day [day], started bank account."
python:
interest_rate = 0.01
player_bank = 1000
day_deposit = 1
"I have $1000."
$ day = 2
"Day [day]."
python:
n = day - day_deposit
player_bank *= pow(1+interest_rate,n)
"I now have $ [player_bank]."
return
Code: Select all
player_bank = round(player_bank, 2) # round to 2 decimals
So, in this line you rounded the 'player_bank' variable
Code: Select all
$player_bank = round(player_bank, 2) # round to 2 decimalsCode: Select all
label banktest:
$ day = 1
"I think I'll open a bank account."
"Day [day], started bank account."
$ player_bank = 1000.0
python:
interest_rate = 0.01
day_deposit = 1
"I have $ [player_bank:.2f]"
$ day = 2
"Day [day]."
$ player_bank *= pow(1+interest_rate,1)
"I now have $ [player_bank:.2f]."
$ day = 3
"Day [day]."
$ player_bank *= pow(1+interest_rate,1)
"I now have $ [player_bank:.2f]."
$ day = 4
"Day [day]."
$ player_bank *= pow(1+interest_rate,1)
"I now have $ [player_bank:.2f]."
$ day = 5
"Day [day]."
$ player_bank *= pow(1+interest_rate,1)
"I now have $ [player_bank:.2f]."
$ day = 100
"Day [day]."
$ player_bank *= pow(1+interest_rate,100-5)
"I now have $ [player_bank:.2f]."
Code: Select all
init python:
import math
def _calculate_interest(_sum, rate, length=1., freq=1.):
"""
:_sum:
Principal sum.
:rate:
Nominal annual interest rate.
:length:
Overall length of time the interest is applied.
:freq:
Compounding frequency per unit of time.
(Can be infinite).
"""
_sum, rate, length, freq = map(float, (_sum, rate, length, freq))
assert (freq > .0)
if math.isinf(freq):
return (_sum * math.exp((rate * length)))
return (_sum * ((1. + (rate / freq)) ** (length * freq)))
def _input_positive_int(*args, **kwargs):
kwargs["allow"] = tuple(map(unicode, xrange(10)))
while True:
value = renpy.input(*args, **kwargs)
if not value:
continue
value = int(value)
if value > 0:
return value
d = Character("Depositor")
e = Character("Bank employee")
_current_year = 2020
my_money = 1.
money_on_account = .0
label start:
d "Yo! I want to make a deposit in your bank."
e "Hey! It's great! How much do you want to invest?"
$ deposit_sum = _input_positive_int("So... How much?")
d "I want to invest $[deposit_sum:.2f]."
if deposit_sum > my_money:
e "You don't have such money. You look like a person who has only $[my_money:.2f]."
$ deposit_sum = my_money
e "For how long do you want to open a deposit?"
else:
e "Wow! Such money!!! For how long?"
$ deposit_len = _input_positive_int("So... How long?", default="100")
d "[deposit_len] years!!!"
$ interest_rate = round(renpy.random.uniform(.005, .2), 4)
e "Using the most modern technology with the codename \"renpy.random\", I calculated the best interest rate for you. You can make a deposit with a rate of [interest_rate:.2%%]!"
$ _result_sum = _calculate_interest(deposit_sum, interest_rate, deposit_len)
$ total_profit = _result_sum - deposit_sum
e "Taking the above into account, in [deposit_len] years you will have $[_result_sum:.2f] on your deposit.{w} Are you happy?{w} You should be happy, because you will earn $[total_profit:.2f] by investing only $[deposit_sum:.2f]."
$ my_money -= deposit_sum
$ money_on_account += deposit_sum
$ deposit_start_year = _current_year
d "Sounds good, I'll go wait in your hall."
e "Will you wait in the hall for [deposit_len] years?.."
d "Yep! I think it will be fun! Let's wait together!"
e "..."
e "No."
"..."
while True:
$ _current_year += 1
"[_current_year]..."
$ money_on_account = _calculate_interest(money_on_account, interest_rate)
if (_current_year - deposit_start_year) >= deposit_len:
d "I waited, sitting in the hall. During this time the bank went bankrupt, but if it was not, I would have taken my $[money_on_account:.2f] today. Okay, bad luck, I'll go home."
return
d "A year has passed. I have $[money_on_account:.2f] on my account."
Users browsing this forum: No registered users