Re: [Tutor] home_finance.py

2007-09-26 Thread Eric Walker
I think you need to check to see if the remaining amount is less than the 
payment amount.

Eric...

Christopher Spears [EMAIL PROTECTED] wrote: I'm working on a problem in 
Chapter 5 of Core Python
Programming(2nd Edition).  I am supposed to write a
script that take an opening balance and a monthly
payment from the user.  The script then displays the
balance and payments like so:


Enter opening balance: 100
Enter monthly payment: 16.13
Amount  Remaining
Pymnt#  PaidBalance
0   0.00100.00
1   16.13   83.87
2   16.13   67.74
3   16.13   51.61
4   16.13   35.48
5   16.13   19.35
6   16.13   3.22
73.22   0.00

Here is what I have written so far:

#!/usr/bin/env python

balance = float(raw_input(Enter opening balance: ))
payment = float(raw_input(Enter monthly payment: ))

print \tAmount\tRemaining
print Pymnt#\tPaid\tBalance

payment_num = 0
print %d\t%.2f\t%.2f % (payment_num,0,balance)

while balance = 0:
payment_num = payment_num + 1
if balance  0:
balance = balance - payment
print %d\t%.2f\t%.2f %
(payment_num,payment,balance)
else:
payment = balance
 balance = balance - payment
print %d\t%.2f\t%.2f %
(payment_num,payment,balance)
 
This is what my script displays:

Enter opening balance: 100
Enter monthly payment: 16.13
Amount  Remaining
Pymnt#  PaidBalance
0   0.00100.00
1   16.13   83.87
2   16.13   67.74
3   16.13   51.61
4   16.13   35.48
5   16.13   19.35
6   16.13   3.22
7   16.13   -12.91

I'm not sure how to solve this problem.  Apparently,
trying to catch the remaining balance when it becomes
negative doesn't work!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


   
-
Luggage? GPS? Comic books? 
Check out fitting  gifts for grads at Yahoo! Search.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] home_finance.py

2007-09-26 Thread Ricardo Aráoz
Eric Walker wrote:
 I think you need to check to see if the remaining amount is less than
 the payment amount.
 
 Eric...

Or just subtract the minimum between the remaining amount and the
payment amount. See below

 
 */Christopher Spears [EMAIL PROTECTED]/* wrote:
 
 I'm working on a problem in Chapter 5 of Core Python
 Programming(2nd Edition). I am supposed to write a
 script that take an opening balance and a monthly
 payment from the user. The script then displays the
 balance and payments like so:
 
 
 Enter opening balance: 100
 Enter monthly payment: 16.13
 Amount Remaining
 Pymnt# Paid Balance
 0 0.00 100.00
 1 16.13 83.87
 2 16.13 67.74
 3 16.13 51.61
 4 16.13 35.48
 5 16.13 19.35
 6 16.13 3.22
 7 3.22 0.00
 
 Here is what I have written so far:
 
 #!/usr/bin/env python
 
 balance = float(raw_input(Enter opening balance: ))
 payment = float(raw_input(Enter monthly payment: ))
 
 print \tAmount\tRemaining
 print Pymnt#\tPaid\tBalance
 
 payment_num = 0
 print %d\t%.2f\t%.2f % (payment_num,0,balance)
 
 while balance = 0:
 payment_num = payment_num + 1
 if balance  0:

 balance = balance - payment
Instead of this ^^^ line you should have :
  balance = balance - min(balance, payment)
And I guess that would be it.

 print %d\t%.2f\t%.2f %
 (payment_num,payment,balance)
 else:
 payment = balance
 balance = balance - payment
 print %d\t%.2f\t%.2f %
 (payment_num,payment,balance)
 
 This is what my script displays:
 
 Enter opening balance: 100
 Enter monthly payment: 16.13
 Amount Remaining
 Pymnt# Paid Balance
 0 0.00 100.00
 1 16.13 83.87
 2 16.13 67.74
 3 16.13 51.61
 4 16.13 35.48
 5 16.13 19.35
 6 16.13 3.22
 7 16.13 -12.91
 
 I'm not sure how to solve this problem. Apparently,
 trying to catch the remaining balance when it becomes
 negative doesn't work!
 ___
 Tutor maillist - Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 
 
 
 Luggage? GPS? Comic books?
 Check out fitting gifts for grads
 http://us.rd.yahoo.com/evt=48249/*http://search.yahoo.com/search?fr=oni_on_mailp=graduation+giftscs=bz
 at Yahoo! Search.
 
 
 
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] home_finance.py

2007-09-25 Thread Christopher Spears
I'm working on a problem in Chapter 5 of Core Python
Programming(2nd Edition).  I am supposed to write a
script that take an opening balance and a monthly
payment from the user.  The script then displays the
balance and payments like so:


Enter opening balance: 100
Enter monthly payment: 16.13
Amount  Remaining
Pymnt#  PaidBalance
0   0.00100.00
1   16.13   83.87
2   16.13   67.74
3   16.13   51.61
4   16.13   35.48
5   16.13   19.35
6   16.13   3.22
73.22   0.00

Here is what I have written so far:

#!/usr/bin/env python

balance = float(raw_input(Enter opening balance: ))
payment = float(raw_input(Enter monthly payment: ))

print \tAmount\tRemaining
print Pymnt#\tPaid\tBalance

payment_num = 0
print %d\t%.2f\t%.2f % (payment_num,0,balance)

while balance = 0:
payment_num = payment_num + 1
if balance  0:
balance = balance - payment
print %d\t%.2f\t%.2f %
(payment_num,payment,balance)
else:
payment = balance
balance = balance - payment
print %d\t%.2f\t%.2f %
(payment_num,payment,balance)

This is what my script displays:

Enter opening balance: 100
Enter monthly payment: 16.13
Amount  Remaining
Pymnt#  PaidBalance
0   0.00100.00
1   16.13   83.87
2   16.13   67.74
3   16.13   51.61
4   16.13   35.48
5   16.13   19.35
6   16.13   3.22
7   16.13   -12.91

I'm not sure how to solve this problem.  Apparently,
trying to catch the remaining balance when it becomes
negative doesn't work!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] home_finance.py

2007-09-25 Thread Ian Witham
On 9/26/07, Christopher Spears [EMAIL PROTECTED] wrote:

 I'm working on a problem in Chapter 5 of Core Python
 Programming(2nd Edition).  I am supposed to write a
 script that take an opening balance and a monthly
 payment from the user.  The script then displays the
 balance and payments like so:


 Enter opening balance: 100
 Enter monthly payment: 16.13
 Amount  Remaining
 Pymnt#  PaidBalance
 0   0.00100.00
 1   16.13   83.87
 2   16.13   67.74
 3   16.13   51.61
 4   16.13   35.48
 5   16.13   19.35
 6   16.13   3.22
 73.22   0.00

 Here is what I have written so far:

 #!/usr/bin/env python

 balance = float(raw_input(Enter opening balance: ))
 payment = float(raw_input(Enter monthly payment: ))

 print \tAmount\tRemaining
 print Pymnt#\tPaid\tBalance

 payment_num = 0
 print %d\t%.2f\t%.2f % (payment_num,0,balance)

 while balance = 0:
 payment_num = payment_num + 1
 if balance  0:


You have: if balance  0:

You should be checking whether the remaining balance is greater than the
payment amount, not whether it is greater than 0.
This is probably just a typo as it looks like you're on the right track.


Ian
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor