Home Python - Loop printing too many times when reading from an imported file
Reply: 0

Python - Loop printing too many times when reading from an imported file

user1237
1#
user1237 Published in May 21, 2018, 3:04 am

Im writing a program to output a table that calculates pay roll. it is reading from an imported file.

The file I'm using to test contains:

  • Barb,Moran,51,12.85
  • Joy,Rinehimer,30,9.35
  • Joe,Bellucci,45,9.55
  • Dave,Flaim,37,17.70

The idea here was to take each line and split it by the , and then go through position by position to print what I need to. Here is the portion of my code that I think contains the issue:

def getFile():
    filename = input("Please enter the employee file name: ")
    print()
    infile = open(filename, "r")
    return infile

def outputs(infile):
    paylist = []
    count = 0

    for lines in infile:
        individual = lines.split(",")
        for pos in individual:
            first = ("{0:7}".format (individual[0]))
            print(first, end = "")

            last = ("{0:12}".format(individual[1]))
            print(last, end = "")

            hours = ("{0:6}".format(individual[2]))
            print(hours, end = "")

            wage = ("{0:6}".format(individual[3]))
            print ("$",wage, end = "")

When I run it, it outputs all of the correct values but 4 times over

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.559809 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO