#๐Ÿ”’ Issue with my interest calculator - Beginnner

85 messages ยท Page 1 of 1 (latest)

violet wadi
#

Either my code is wrong or my math is wrong lol. Can't figure out for the past hour... PLEASE do not give out the answers directly, I would appreciate it. Indirect helps only, I'd like to improve myself.

Code:

loan = 1000

for years in range(10):
    answer = (5/100) * loan * years
    print(f"Year {years + 1} is ${answer + loan}")```
vagrant pastureBOT
#

@violet wadi

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

trail notch
#

what does it do, and how does that differ from what you want it to do?

violet wadi
#

Well on internet I got this project called loan calculator. It's suppose to be the following response:

trail notch
#

||pretty sure it's your math that's wrong, not your code||

violet wadi
#

I end up getting this

violet wadi
#

Tried looking for formular across internet as well. I don't get it it's still not giving the result

#

Percentage/100 * loan

trail notch
#

so imagine Robert gets a 5% raise every single year, the bastard

#

that's basically what you should be doing

violet wadi
#

answer * 2?

trail notch
#

no idea what you're asking

violet wadi
#

My brain is not braining lol

#

It's suppose to be doubling every year

trail notch
#

what is?

violet wadi
#

5% more

violet wadi
trail notch
#

what kind of interest doubles every year?!

violet wadi
#

Lol loan

raw niche
#

Your for loop isn't using the previous years result when calculating the next one, you're approximating by adding 5% for each year, but that's not the same.

open pelican
trail notch
#

never heard of a loan like that.

violet wadi
#

By double I meant every years it gets +5%

trail notch
#

typically, interest is a constant percentage, like 5%/year

open pelican
trail notch
violet wadi
# violet wadi No?

How about we start by this. What is suppose to be the formula for the interest here. Is the one shown here wrong?

raw niche
#

You're doing:
1000+0.05ร—1000=1050
1050+0.05ร—1000=1100
You want:
1000+0.05ร—1000=1050
1050+0.05ร—1050=1102.5

violet wadi
#

And 1050 is suppose to increase every year

#

Let me give it a try

#

Ah

#

SSo here's my problem

#

I have the formula I just don't know how to loop it

soft musk
#

what formula

violet wadi
#

1000+0.05ร—1000=1050

#

loan + 0.05 * loan = answer

soft musk
#

what loop

violet wadi
#

I'm suppose to loop it where every year it increases the interest of 5%

soft musk
#

no loop needed

open pelican
#

So have you made any changes to your code? Does it work?

violet wadi
#

Changes yea several, working nope still figuring

violet wadi
open pelican
#

I think it's more useful to do it with loops if the goal is to learn programming

violet wadi
#

Right

#

I mean I'm aware the power up could double it every time

#

But I'd like to make the progress in coding

open pelican
#

Show your current code if you want a hint

violet wadi
#
loan = 1000

for years in range(10):
    answer = loan + 0.05 * loan
    total = answer + 0.05 * answer
    print(f"Year {years + 1} is ${total}")```
soft musk
#

the scope of answer and total prevents it from being changed

violet wadi
#

Yea I noticed cuz every year it shows the same amount

soft musk
#

so one of them needs to come out of the loop

violet wadi
#

Hm

#

Throw out the answer

soft musk
violet wadi
#

I was able to change the concept

#

Here's the recent code

#
loan = 1000
percentage  = 0.05
for i in range(10):
  loan+=(loan*percentage)
  print("Year {i+1} is {loan}")
open pelican
#

What's the output of this code?

soft musk
#

loan+=(loan*percentage)
this calculation is unorthodox

#

and your string isnt formatted

violet wadi
open pelican
#

So seems correct

violet wadi
#

Yea

#

Yea

#

It's weird the formula is loan * percentage and then +1 to the loan

#

Different formula from what's out there lol

#

Anyways thanks

soft musk
#

you could change the range of i to be range(1, 11)

#

and for loan * percentage you would need to make the percentage 1.05

violet wadi
#

Y could hut wanted to get use to +=

soft musk
#

sure

violet wadi
#

Typos my bad I switched to phone

soft musk
#

you could use *= though

violet wadi
soft musk
#

loan *= percentage

violet wadi
#

Various ways to do I guess

mighty hemlock
soft musk
#

you dont round money

soft musk
#

some weird rounding

vagrant pastureBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.