Hello everyone im pretty new to python and im having some trouble creating a program that takes a file containing numbers and imports it into python and makes it look like a table. the table is supposed to look something like this when the program is run. basically i figure the best way to do this would be to import the table from excell but i have no idea how to do that, everything else ive found on the net didnt work for me.
Model : 1 2 3 4 5 6 7 8 : Avg Totals
-------------------------------------------------------
1 : O O 2 0 5 6 3 0 : x.x xx
2 : 5 1 9 0 0 2 3 2 : x.x xx
3
4
5
6
7
8
9
10
--------------------------------------------------------
Average: x.x x.x x.x
Maximum:
Totals :
and this is my program so far it is basically what the professor made up to show columns and rows of numbers
and i cant even get that to work.. ill answer any questions to clarify, sorry if i didn't make enough sense. thanks for anyone who can help me!
# Filename: Houses.py
# Author:
# Date: 12/01/2012
# Purpose: To show the number of sales in a month,
# sold by a group of individuals
def intro():
print()
print("Program to output a yearly report of house sales.")
print("Written by .")
print()
def getfile():
filename = input("Enter the file name: ") # i receve an error here no matter if i use .xls
print() # or .txt usually about invalid token or something else when using excell
infile = open(filename, "r")
print()
print("For the file", filename, end="")
print(":")
print()
return infile
def getnumber(infile):
numbers = []
i = 0
for line in infile:
list = line.split()
row = []
for num in list:
row.append(eval(num))
numbers.append(row)
i = i + 1
print(numbers)
print()
return numbers
def printresults(numbers):
for row in numbers:
total = 0
for item in row:
total = total + item
print("{0:3}".format(item), end="")
print("{0:4}".format(total))
def main():
intro()
infile = getfile()
numbers = getnumber(infile)
printresults(numbers)
main()