Guest User

Untitled

a guest
Oct 21st, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. def Minimum(task):
  2.    
  3.     print('hello')
  4.    
  5.    
  6. def open_file(task):
  7.    
  8.        
  9.  
  10.     while(True):
  11.         try:
  12.             file_name = str(input('Enter a file name: '))
  13.             file_obj = open(file_name,'r')
  14.             L = []
  15.                
  16.             break
  17.            
  18.         except FileNotFoundError:
  19.             print('Error. File not found.')
  20.        
  21.     for file_line in file_obj:
  22.         L.append([float(x) for x in file_line.split(',')])
  23.            
  24.          
  25.     # make sure to close file_obj.close()
  26.  
  27.     index = 0
  28.     while(index < len(L)):
  29.         if(len(L[0]) == len(L[index])):
  30.             index+=1
  31.         else:
  32.             return('Data could not be loaded (the number of columns is not the same for all rows).')
  33.             break
  34.        
  35.        
  36.     print()
  37.     col_num = len(L[0])
  38.     row_index = 1
  39.     alpha_index = 0
  40.     alpha_str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  41.     blank = ' '
  42.  
  43.     print('|{:^5}'.format(blank), end = '')
  44.        
  45.              
  46.     while(alpha_index < col_num):
  47.         print('|{:^10}'.format(alpha_str[alpha_index]), end = '')
  48.         alpha_index +=1
  49.        
  50.     print()
  51.  
  52.     for row in L:
  53.            
  54.         print('|{:^5}'.format(row_index), end ='')
  55.            
  56.         for elem in row:
  57.                
  58.             print('|{:^10.2f}'.format(elem),end = '')
  59.         row_index+=1  
  60.         print()
  61.  
  62.            
  63.  
  64.     print()
  65.        
  66.     return(L)
  67. def main():
  68.    
  69.     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')
  70.    
  71.     while(True):
  72.        
  73.         task = (input('Your choice: '))
  74.         if(task == '0' or task == '1' or task == '2' or task == '3' or task == '4' or task == '5' or task == '6'
  75.         or task == '7'or task == '8'or task == '9' or task == '10' or task == '11'):
  76.  
  77.             break
  78.    
  79.     if(task == '0'):
  80.         pass
  81.     if(task == '1'):
  82.         numlist = open_file(task)
  83.         print(numlist)
  84.         main()
  85.     elif(task =='2'):
  86.         Minimum(task)
  87.         main()
  88.        
  89.  
  90. main()
Advertisement
Add Comment
Please, Sign In to add comment