data.txt file:
Lambert 34 10.50
Osborne 22 6.25
Giacometti 5 100.70
f = input("Enter the file name: ")
f1 = open(f, 'r')
print("Name" , "Hours", "Total Pay")
for line in f1:
print(line)
current output:
Enter the file name: data.txt
Name Hours Total Pay
Lambert 34 10.50
Osborne 22 6.25
Giacometti 5 100.70
The issue with this code is that it needs to be printed out in tabular format. With headers of name, hours, total pay, with the contents of the file under it.
I know how to open the file, and print it by line, but I have no idea how I am going to make it like a table format. An example of the output is going to be like this:
Enter the file name: data.txt
Name Hours Total Pay
Lambert 34 357.00
Osborne 22 137.50
Giacometti 5 503.50
How would I do this? I'm almost there, I'm pretty sure I need to make my first print statement longer, and make an array, such as this from another stack overflow post
data = np.array([[1, 2, 1],
[0, 1, 0],
[2, 4, 2]])
But the issue is how would I make an array from contents from a text file?
Thank you