Coding help on Listing

This is the place for queries that don't fit in any of the other categories.

Coding help on Listing

Postby zahrein » Mon Apr 15, 2013 11:16 pm

Code: Select all
items =['Loan Kereta','Loan Rumah','fees rumah','Qdees fees','Nakfah Zura','PTPTN','maxis','Credit card',
       'zakat']

for item in items:
    payments=int(raw_input('Enter the payments for %s '% item))
    print 'The payment is %d' % payments


Hi Im a newbie and need some help. Actually i want to add all the payments that we enter/insert at the end of items. This code is for my payments every month. If i have the total amount that i pay , this is my 1st code in python.
Thanks in advance.
zahrein
 
Posts: 15
Joined: Wed Apr 03, 2013 1:45 am

Re: Coding help on Listing

Postby setrofim » Tue Apr 16, 2013 5:13 am

Code: Select all
items =['Loan Kereta','Loan Rumah','fees rumah','Qdees fees','Nakfah Zura','PTPTN','maxis','Credit card',
        'zakat']

total_payments = 0
for item in items:
    payments=int(raw_input('Enter the payments for %s '% item))
    print 'The payment is %d' % payments
    total_payments += payments

print "Total payments this month:", total_payments
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Coding help on Listing

Postby zahrein » Tue Apr 16, 2013 6:26 am

Thanks..now i know how to use '+=' operator.
zahrein
 
Posts: 15
Joined: Wed Apr 03, 2013 1:45 am


Return to General Coding Help

Who is online

Users browsing this forum: Dragonization, W3C [Linkcheck] and 5 guests