I'm trying to find and print the minimum value for n that satisfies ca >= cb:
ap = 80000
bp = 200000
at = 1.03
bt = 1.015
n = 1
ca = ap*at*n
cb = bp*bt*n
while cb > ca:
n = n + 1
print(n)
The code just runs and prints n + 1 indefinitely, though. What is the correct approach to this problem?
ifstatementcaandcbwere one-time events. They don't auto-update in response to later changes ton, which seems to be what you were expecting to happen. You need to recalculate them each time through the loop