Advertisement
Guest User

Untitled

a guest
Oct 21st, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. rite a program that simulates some of the data manipulation performed by Excel. In particular your program should do the following:
  2. Display a menu with the options below:
  3. "Open": Opens a file. When this option is selected, the user will be asked for the filename. If the file reads successfully, the data from the file will be printed as a table nicely formatted. A file will read sucessfully if it exists and can be opened and the data in it constitutes a table (each line will have the same number of pieces of information separated by commas)
  4. good file (each line has 4 numbers):
  5. 1.2, 4.3, 7, 0
  6. 3, 5, 8.2, 9
  7.  
  8.  
  9. bad file (some lines have 4 numbers and other have 3 numbers):
  10. 1.2, 4.3, 7, 0
  11. 3, 5, 8.2
  12. The data that is read from the file should be stored in the program as a list of lists that has as many inner lists as lines in the file (one inner list for each line in the file). In the good example above, the data should be stored as: [[1.2, 4.3, 7, 0], [3, 5, 8.2, 9]]. In this list some numbers are integers and some are floats. If you prefer, you can read all the numbers as floats (e.g.: [[1.2, 4.3, 7, 0], [3, 5, 8.2, 9]]).
  13. In the table that is printed, rows are numbered and columns are annotated with letters (like in Excel). The user will be using the numbers and the letters to indicate rows or columns.
  14. In order to speed up the testing of my program, if the user does not enter a filename (they hit Enter without having typed anything), by default my program will use the filename data1.txt. See the 3-rd coice of menu option 1 from the sample run below.
  15. Find and print the minimum value in a row (given the row number) or a column (given the column letter).
  16. Find and print the maximum value in a row (given the row number) or a column (given the column letter).
  17. Compute and print the sum of all the elements in a row or a column
  18. Compute and print the average of all the elements in a row or a column
  19. Sort the whole table by the values in a certain column (reorder the rows s.t. the values in that column are sorted in ascending or descending order). The user will give 2 letters separated by a space: the column letter and another letter that spceifies the ordering. The letter 'a' or 'A' indicate ascending order and 'd' or 'D' would indicate descending order. If any of the letters for the column and for the order is invalid, the table will be left as is ( NO reordering will be performed). Hint: see how Python sorts a list of lists (the principle is the same as for sorting/comparing strings).
  20. Insert a row or a column, right before the one indicated by the user. The user indicates a row by a number and a column by a letter. The inserted row or column should contain zeros. NOTE that you can insert the last column or row. In that case, the indexes are not valid for the original list, but they would be for teh new list and thus you should recognize them as valid. See the examples of inserting row 6 in a table of 5 rows and column H in a table with F columns. But there are still invalid indexes to be checked for. See the example of attempting to insert row 12 in a table of 6 rows.
  21. Delete a row or a column indicated by the user (with a number for a row or a letter for a column).
  22. Modify an element at a certain cell in the table. The user will specify the row, the column and the new value (e.g.: 3,B, 2.6).
  23. "Save": Save the current data in the same file that it was loaded from (it will overwrite the original file with the current data).
  24. "Save As": Save this data in another file. When this option is selected, the user should be asked to enter a filename and then the program will save the data in a file with that name. You should check that the file does not already exist. If it exists the program should let the user know that and ask for a confirmation to save (and thus to overwrite that file). You can use the 'os.path.isfile()' function to check that a file exists.
  25. "Exit": Finish/stop the program (exit from the menu loop).
  26.  
  27. Example:
  28.  
  29. 1 - Open and load from a file
  30. 2 - Minimum
  31. 3 - Maximum
  32. 4 - Sum
  33. 5 - Average
  34. 6 - Sort (by column, ascending or descending)
  35. 7 - Insert
  36. 8 - Delete
  37. 9 - Modify an element
  38. 10 - Save
  39. 11 - Save as (specify new file name)
  40. 0 - Exit
  41. Your choice: 1
  42. Enter a filename (if you hit enter, data1.txt will be opened):
  43.  
  44.  
  45.  
  46. -----------------------------------------------
  47. | | A | B | C | D | E |
  48. -----------------------------------------------
  49. | 1 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 |
  50. | 2 | 6.00 | 7.00 | 8.00 | 9.00 | 0.00 |
  51. | 3 | 1.10 | 2.20 | 3.30 | 0.10 | 0.30 |
  52. -----------------------------------------------
  53.  
  54.  
  55. Example:
  56.  
  57.  
  58.  
  59. -----------------------------------------------
  60. | | A | B | C | D | E |
  61. -----------------------------------------------
  62. | 1 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 |
  63. | 2 | 6.00 | 7.00 | 8.00 | 9.00 | 0.00 |
  64. | 3 | 1.10 | 2.20 | 3.30 | 0.10 | 0.30 |
  65. -----------------------------------------------
  66. 1 - Open and load from a file
  67. 2 - Minimum
  68. 3 - Maximum
  69. 4 - Sum
  70. 5 - Average
  71. 6 - Sort (by column, ascending or descending)
  72. 7 - Insert
  73. 8 - Delete
  74. 9 - Modify an element
  75. 10 - Save
  76. 11 - Save as (specify new file name)
  77. 0 - Exit
  78. Your choice: 2
  79. Enter a row (as a number) or a column (as an uppercase letter): D
  80. Minimum is: 0.1
  81.  
  82.  
  83. Example:
  84.  
  85. 1 - Open and load from a file
  86. 2 - Minimum
  87. 3 - Maximum
  88. 4 - Sum
  89. 5 - Average
  90. 6 - Sort (by column, ascending or descending)
  91. 7 - Insert
  92. 8 - Delete
  93. 9 - Modify an element
  94. 10 - Save
  95. 11 - Save as (specify new file name)
  96. 0 - Exit
  97. Your choice: 6
  98. Enter a column and the order(a/A-ascending, d/D-descending) separated by comma (e.g.: D,a) : D,a
  99.  
  100.  
  101.  
  102. -----------------------------------------------
  103. | | A | B | C | D | E |
  104. -----------------------------------------------
  105. | 1 | 1.10 | 2.20 | 3.30 | 0.10 | 0.30 |
  106. | 2 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 |
  107. | 3 | 6.00 | 7.00 | 8.00 | 9.00 | 0.00 |
  108. -----------------------------------------------
  109.  
  110.  
  111. Example:
  112.  
  113.  
  114. 1 - Open and load from a file
  115. 2 - Minimum
  116. 3 - Maximum
  117. 4 - Sum
  118. 5 - Average
  119. 6 - Sort (by column, ascending or descending)
  120. 7 - Insert
  121. 8 - Delete
  122. 9 - Modify an element
  123. 10 - Save
  124. 11 - Save as (specify new file name)
  125. 0 - Exit
  126. Your choice: 7
  127. Enter a row (as a number) or a column (as an uppercase letter): 1
  128.  
  129.  
  130.  
  131. -----------------------------------------------
  132. | | A | B | C | D | E |
  133. -----------------------------------------------
  134. | 1 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
  135. | 2 | 6.00 | 7.00 | 8.00 | 9.00 | 0.00 |
  136. | 3 | 1.00 | 2.00 | 3.00 | 4.00 | 5.00 |
  137. | 4 | 1.10 | 2.20 | 3.30 | 0.10 | 0.30 |
  138. -----------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement