Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def open_file():
- while(True):
- try:
- file_name = str(input('Enter a file name: '))
- file_obj = open(file_name,'r')
- L = []
- break
- except FileNotFoundError:
- print('Error. File not found.')
- for file_line in file_obj:
- L.append([float(x) for x in file_line.split(',')])
- # make sure to close file_obj.close()
- index = 0
- while(index < len(L)):
- if(len(L[0]) == len(L[index])):
- index+=1
- else:
- return('Data could not be loaded (the number of columns is not the same for all rows).')
- break
- print()
- col_num = len(L[0])
- row_index = 1
- alpha_index = 0
- alpha_str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- blank = ' '
- print('|{:^5}'.format(blank), end = '')
- while(alpha_index < col_num):
- print('|{:^10}'.format(alpha_str[alpha_index]), end = '')
- alpha_index +=1
- print()
- for row in L:
- print('|{:^5}'.format(row_index), end ='')
- for elem in row:
- print('|{:^10.2f}'.format(elem),end = '')
- row_index+=1
- print()
- print()
- return(L)
- def main():
- print('1 - Open and load from a file\n2 - Minimum\n3 - Maximum\n4 - Sum\n5 - Average\n6 - Sort (by column, ascending or decending)\n7 - Insert\n8 - Delete\n9 - Modify an element\n10 - Save\n11 - Save As (specify new file name)\n0 - Exit')
- while(True):
- task = (input('Your choice: '))
- if(task == '0' or task == '1' or task == '2' or task == '3' or task == '4' or task == '5' or task == '6'
- or task == '7'or task == '8'or task == '9' or task == '10' or task == '11'):
- break
- if(task == '0'):
- pass
- if(task == '1'):
- numlist = open_file()
- print(numlist)
- main()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement