- #1
Mr Davis 97
- 1,462
- 44
I need to implement the following pseudocode in Python:
However, this psudocode uses the for loop in the style of a C language. Python uses a foreach type loop, which takes a variable and iterates over a list. We typically use `range()` for this for the list, but this only takes integers as arguments, while the for loop I am trying to implement needs to take floating point numbers. Is there any simple way in which I can use a typical Python for loop to implement this? Or will I have to fall back on using a while loop with a counter variable?
Code:
N=5 #where N is number of years
For (rate = 0.05, rate <= 0.15, rate = rate + 0.05)
For (principal=10000, principal <=15000, principal=principal+1000)
simple = principal * (1 + rate * N) #where N is number of years
compound = principal * (1 + rate) ^ N
print simple + “ “ + compound
EndFor
EndFor
However, this psudocode uses the for loop in the style of a C language. Python uses a foreach type loop, which takes a variable and iterates over a list. We typically use `range()` for this for the list, but this only takes integers as arguments, while the for loop I am trying to implement needs to take floating point numbers. Is there any simple way in which I can use a typical Python for loop to implement this? Or will I have to fall back on using a while loop with a counter variable?