Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do in Python
#5
Please help. Show me how to do this. Have indented code and get no complaint.
As it is still only reports last item. What is correct?
The plan is to work with 11 categories.

tia

Example of expenses-18.

012118,1,1.00,1
022218,2,2.22,2
032318,3,33.33,3
042418,4,44.44,3

#!/usr/bin/python
x = 0
tamt = 0
with open('expenses-18', 'r') as file:
    for line in file:
      pdate,catg,amt,howp = line.split(",")
      catg = int(catg)
      tamt = tamt + float(amt)
      x = x + 1
      print 'cnt > ',x ,'catg  :', catg
    if catg == 1:
       print '*    line > ', line 
    elif catg == 2:
       print '**   line > ', line
    elif catg == 3:
       print '***  line > ', line
    elif catg == 4:
       print '**** line > ', line

       print ' ##\n'
       print 'total amt > ',tamt
Reply


Messages In This Thread
How to do in Python - by oldcity - Apr-26-2018, 03:20 PM
RE: How to do in Python - by nilamo - Apr-26-2018, 03:45 PM
RE: How to do in Python - by oldcity - Apr-27-2018, 03:07 PM
RE: How to do in Python - by nilamo - Apr-27-2018, 03:22 PM
RE: How to do in Python - by oldcity - May-24-2018, 03:53 PM
RE: How to do in Python - by snippsat - May-24-2018, 06:22 PM
RE: How to do in Python - by nilamo - May-24-2018, 06:39 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020