Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incomplete Output
#1
Using Linux Mint 18.2 and running programs from Python 3.5 which is the default for 18.2.
Upon of doing python Basic-Menu.py and making selection '3' the file names
are not presented. On entering a number of 0 to and entering '1' for file name,
Next choice is month number using '1' again. The results displayed do not
include: filename, # Items:, Month Expenses:, Paid Cash >, Paid Check >, Paid C Card >.
But running the program from the command line all is displayed correctly.
How to remedy this would be helpful.
tia
oldcity

##############################################

 #!/usr/bin/python3
#                   Basic-Menu.py
 import subprocess
 ans=True
 while ans:
     print ("""
     1.Add Expenses
     2.View/Print Expenses
     3.Verify Entries
     4.Exit/Quit
     """)
     ans=raw_input("What would you like to do? ")
     print(" ") 
     if ans=="1": 
#        subprocess.call("./Add-Expenses.py")
        print(" ") 
     elif ans=="2":
#          subprocess.call("./Expense-Rpt.py")
        print(" ") 
     elif ans=="3":
          subprocess.call("./Verify-Expenses.py")
     elif ans=="4":
          print(" Goodbye")
          break 
     elif ans !="":
        print(" Not Valid Choice Try again") 

##############################################

 oldcity ~/MyPython $ python Basic-Menu.py

    1.Add Expenses
    2.View/Print Expenses
    3.Verify Entries
    4.Exit/Quit
    
 What would you like to do? 3
 

 file line count :


       Choose file #  0 to 


       Enter Choice 1


       Enter Month to Verify [1-12]: 1



       Jan    FP&L        16.42     2
       Jan    PLAN-D      72.00     2
       Jan    AARP       186.63     2
       Jan    DRUGS      125.17     1
       Jan    WATER       16.32     2
       Jan    DIAZ       109.00     2
       Jan    CAR         50.60     2
       Jan    AT&T       124.73     2


              # items:  
       Month Expenses:  


              paid cash > 
             paid check > 
            paid c card > 

 

 Job done 

    1.Add Expenses
    2.View/Print Expenses
    3.Verify Entries
    4.Exit/Quit
    
 What would you like to do? 4
 
 Goodbye
##############################################

 #!/usr/bin/python3
 #
 # Verify-Expenses.py
 #                           10-18-18        3:00 pM
 # 
 open('expenses-18', 'r')
 num_lines = sum(1 for line in open('expenses-18'))
 print ('\n')
 print ('file line count :'), num_lines
 print ('\n')
 #
 cls = 0
 while cls < 22:
    cls+=1
    print ('\n\n')
 col1 = 0
 amt = 0
 month_expenses = 0
 total_expenses = 0
 howp1 = 0
 howp2 = 0
 howp3 = 0
 cnt = 0
 #
 #
 #    Tuple
 line_num = 0
 dyears = []
 with open('Expenses-YY', 'r') as exp_yrs:
      for line in exp_yrs:
         dfiles = line.strip(",")
         dfiles = dfiles.rstrip("\n")
         print ('        '), line_num, ('  '),dfiles
         dyears.append(dfiles,)
         line_num+=1
 #
 #
 print ('\n\n        Choose file #  0 to '),line_num - 1
 fn = int(input('\n\n        Enter Choice '))
 print ('\n\n')
 datafile = (dyears[fn])
 #
 vmm = input('\n\n        Enter Month to Verify [1-12]: ')
 vmm = int(vmm)
 cls = 0
 while cls < 22:
    cls+=1
    print ('\n\n')
 print ('         '),datafile
 print ('\n\n')
 #
 with open( datafile, 'r') as yrs_file:
     for line in yrs_file:
         (pdate,catg,amt,howp) = line.split(',')
         pdate = str(pdate)
         pdate = pdate.strip()
         pdate = str(pdate)
         length = len(pdate)
         catg = catg.strip()
         catg = int(catg)
         amt = amt.strip()
         amt = float(amt)
         howp = howp.strip()
         howp = int(howp)
         mm = pdate[0:2]
         mm = int(mm)
         if (vmm == mm):
           cnt = cnt + 1
           month_expenses = month_expenses + amt
           howp = int(howp)
           month = int(mm)
           monthDict={1:'Jan', 2:'Feb', 3:'Mar', 4:'Apr', 5:'May', 6:'Jun', 7:'Jul', 8:'Aug', 9:'Sep', 10:'Oct', 11:'Nov', 12:'Dec'}
           monthIndex = month
           month = monthDict[monthIndex]
           mcatg = int(catg)
           mcatgDict={1:'AT&T  ', 2:'FP&L  ', 3:'WATER ', 4:'GAS   ', 5:'PLAN-D', 6:'AARP  ', 7:'DIAZ  ', 8:'DRUGS ', 9:'HOUSE ', 10:'CAR   ', 11:'MISC  '}
           mcatgIndex = mcatg
           mcatg = mcatgDict[mcatgIndex]
           if howp == 1:
                howp1 = howp1 + 1
           elif howp == 2:
                howp2 = howp2 + 1
           elif howp == 3:
                howp3 = howp3 + 1
           else:
                blank = 0
           mnth_expenses = ("        %s    %s        %6.2f        %s" % (month,mcatg,amt,howp))
           print (mnth_expenses)
 # 
 print ('\n\n                # items:  '), cnt
 print ('          Month Expenses:  '), month_expenses
 print ('\n')
 print ('                  paid cash > '), howp1
 print ('                 paid check > '), howp2
 print ('                paid c card > '), howp3
 print ('\n \n')
 
 
 
 print ('Job done ')
##############################################

 oldcity ~/MyPython $ python Verify-Expenses.py


 file line count : 72


      0    expenses-16
      1    expenses-17
      2    expenses-18


       Choose file #  0 to  2


       Enter Choice 1


       Enter Month to Verify [1-12]: 1


       expenses-17



       Jan    FP&L        16.42     2
       Jan    PLAN-D      72.00     2
       Jan    AARP       186.63     2
       Jan    DRUGS      125.17     1
       Jan    WATER       16.32     2
       Jan    DIAZ       109.00     2
       Jan    CAR         50.60     2
       Jan    AT&T       124.73     2


              # items:   8
       Month Expenses:   700.87


              paid cash >  1
             paid check >  7
            paid c card >  0


 Job done
 
##############################################
Reply
#2
The calls to print won't display the results as expected because you left some arguments after the closing parenthesis. For example
 print ('file line count :'), num_lines
should be
 print ('file line count :', num_lines)
With your current code, num_lines will be printed with python 2.7 but not with 3.5.
Reply
#3
(Oct-19-2018, 08:22 PM)Gribouillis Wrote: With your current code, num_lines will be printed with python 2.7 but not with 3.5.

They use python2 anyway - look at raw_input on line 14 and also at example how they run the code

@oldcity: python2 is the default one (i.e. when you use python to run the code, it's python2). Use python3 instead.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Part 2 Revised.
Using Linux Mint 18.2 and running programs from Python 3.5 which is the default for 18.2.
Running the program from Basic-Menu.py the tuple in Verify-Expenses.py fails.
But running the program from the command line tuple in Verify-Expenses.py runs correctly.
How to remedy this would be helpful.
tia
oldcity
##############################################

 #!/usr/bin/python3
 #                   Basic-Menu.py
 import subprocess
 ans=True
 while ans:
     print ("""
     1.Add Expenses
     2.View/Print Expenses
     3.Verify Entries
     4.Exit/Quit
     """)
     ans=raw_input("What would you like to do? ")
     print(" ") 
     if ans=="1": 
 #        subprocess.call("./Add-Expenses.py")
        print(" ") 
     elif ans=="2":
 #          subprocess.call("./Expense-Rpt.py")
        print(" ") 
     elif ans=="3":
          subprocess.call("./Verify-Expenses.py")
     elif ans=="4":
          print(" Goodbye")
          break 
     elif ans !="":
        print(" Not Valid Choice Try again")
##############################################

Output:
oldcity ~/MyPython $ python Basic-Menu.py 1.Add Expenses 2.View/Print Expenses 3.Verify Entries 4.Exit/Quit What would you like to do? 3 Choose file # 0 to Enter Choice 1 Job done 1.Add Expenses 2.View/Print Expenses 3.Verify Entries 4.Exit/Quit What would you like to do? 4 Goodbye
##############################################

#!/usr/bin/python3
 #
 # Verify-Expenses.py
 #                           10-20-18        4:00 pM
 while cls < 22:
    cls+=1
    print ('\n\n')
 #
 #    Tuple
 line_num = 0
 dyears = []
 with open('Expenses-YY', 'r') as exp_yrs:
      for line in exp_yrs:
         dfiles = line.strip(",")
         dfiles = dfiles.rstrip("\n")
         print ('        '), line_num, ('  '),dfiles
         dyears.append(dfiles,)
         line_num+=1
 #
 #
 print ('\n\n        Choose file #  0 to '),line_num - 1
 fn = int(input('\n\n        Enter Choice '))
 print ('\n\n')
 datafile = (dyears[fn])
#############################################
Output:
# From command line oldcity ~/MyPython $ python Verify-Expenses.py 0 expenses-16 1 expenses-17 2 expenses-18 Choose file # 0 to 2 Enter Choice
Reply
#5
As Buran said, you're not running python 3, otherwise raw_input() would raise an exception.
Reply
#6
(Oct-20-2018, 09:20 PM)oldcity Wrote: python Verify-Expenses.py
It's been mention in this thread and also in your older Thread that python is Python 2.7 on Mint 18.2.
python3 is Python 3.5 on Mint 18.2.
So to make it clear python3 Verify-Expenses.py,and you replace raw_input() with input().
Reply
#7
Had bad info re: 3. + on my system.
Had bad info to use '#!/usr/bin/python3'
Do not require 3. + for in-house.
Found could call using; import os and the
command os.system(('python filename.py')
from my menu.

Thanks for pushing me to explore this new to me Python.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  incomplete registration Low_Ki_ 5 4,560 May-12-2017, 05:41 PM
Last Post: Low_Ki_

Forum Jump:

User Panel Messages

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