Help with ps1. Really needing help here. I'm looking at the first example ps1a.py. Whats the purpose of the creation of the amountPaid and principal variables within the loop? Not sure how someone can write this on the fly since I'm not able to follow it just by reading it
a prime number can be divised by 2 natural number with no remainder and is > 1. so we can create a function formuling [a%b=o (no reminder)]=MIT then we define that a prime number has a MIT=2. and only now we can create a loof to generate the first 1000th prime number with WHILE. I hope its clear check Ératosthène on wiki
the for loop simulates the passage of time (12 months) amountPaid accumulats minPy - this is how much 'you' have paid with your minimum payments principal is he portion of minPay that actually goes toward paying off your balance
marcosamsterdam: are we talking about the same problem set? first one out of problem set1 where it talks about finding the total amount paid and remaining balance? bwCA: i appreciate your response. I understand what the for loop and the range does but: Why would you declare amountPaid before the loop to 0? Why would you use multiplication in the amountPaid in the for loop? Why would you use division in the principal in the for loop? Why would you use subtraction in the balance variable in the for loop? Sorry for being stubborn, just trying to figure this out. Light bulb hasnt came on yet.
you have to set amountPaid to zero initially because in line 18 it is used on the right side of the equation - comment out line 9 and see what happens this solution asks the user to enter a minimum payment RATE - the minimum monthly payment amount is the current balance times the payment RATE this solution asks for the ANNUAL interest rate - the interest rate per month is the ANNUAL interest rate divided by twelve every month you make a payment. some of that payment goes to interest and some goes to interest. the balance each month after you have made a payment is the balance before the payment minus the portion of the payment that is applied to the principal. when comments are not included in code that you are trying to figure out, you have to keep in mind the context of the problem that is being solved. writing down in words the steps to solve the problem can help figure out code that someone else has written - or code that you wrote six months ago and didn't put comments in - this is also helpful when initially trying to solve a problem with a computer program. everybody approaches solutions from a different angle - sometimes the solutions are more obvious than others. if you are trying to figure out some code and you think you know what it is supposed to do but the program doesn't jive with what you think, look very carefully at what the variable types are and what the variables represent. putting print statements in a program to print variables, calculation results and condition tests is a good troubleshooting tool - this can also help figuring out 'unknown' code.
Join our real-time social learning platform and learn together with your friends!