Because you need to get practice in working out the solutions yourselves I won't post answers from now on. I will be more than happy to discuss them in person, in lecture or lab. 1. Write a program that starts from a list of integers and sorts them in ascending (or descending, depending on what the user wants) order. >>> Here's the list I start from [4, 2, 3, 1, -1, 9, 3, 2] Here's the list sorted [-1, 1, 2, 2, 3, 3, 4, 9] >>> 2. Write a program that reads a string and tabulates the frequency of occurrence of each one of its letters. >>> ================================ RESTART ================================ >>> Please enter input: banana a --> 3 b --> 1 n --> 2 >>> ================================ RESTART ================================ >>> Please enter input: watermelon a --> 1 e --> 2 m --> 1 l --> 1 o --> 1 n --> 1 r --> 1 t --> 1 w --> 1 >>> ================================ RESTART ================================ >>> Please enter input: once upon a time in a far away land there lived an ogre a --> 7 --> 12 c --> 1 e --> 6 d --> 2 g --> 1 f --> 1 i --> 3 h --> 1 m --> 1 l --> 2 o --> 3 n --> 5 p --> 1 r --> 3 u --> 1 t --> 2 w --> 1 v --> 1 y --> 1 >>> 3. Write a program that starts from a list of names and randomly selects them for a number of times, then prints a table that shows how many times each name has been selected. >>> ================================ RESTART ================================ >>> Sample size: 3 Kobe --> 1 Pietrus --> 0 LeBron --> 1 Barkley --> 1 Gasol --> 0 >>> ================================ RESTART ================================ >>> Sample size: 10 Kobe --> 3 Pietrus --> 2 LeBron --> 3 Barkley --> 0 Gasol --> 2 >>> ================================ RESTART ================================ >>> Sample size: 50 Kobe --> 6 Pietrus --> 7 LeBron --> 9 Barkley --> 12 Gasol --> 16 >>> ================================ RESTART ================================ >>> Sample size: 1000 Kobe --> 199 Pietrus --> 192 LeBron --> 206 Barkley --> 217 Gasol --> 186 >>> 4. Redo problem 3 where the tabulation is reported in order by the number of times each person has been selected. >>> ================================ RESTART ================================ >>> Sample size: 3 LeBron --> 2 Kobe --> 1 Pietrus --> 0 Gasol --> 0 Barkley --> 0 >>> >>> ================================ RESTART ================================ >>> Sample size: 15 LeBron --> 4 Barkley --> 4 Pietrus --> 3 Gasol --> 3 Kobe --> 1 >>> ================================ RESTART ================================ >>> Sample size: 300 Pietrus --> 67 Kobe --> 64 Gasol --> 63 Barkley --> 59 LeBron --> 47 >>> ================================ RESTART ================================ >>> Sample size: 1000 LeBron --> 215 Barkley --> 204 Kobe --> 196 Pietrus --> 194 Gasol --> 191 >>> ================================ RESTART ================================ >>> Sample size: 10000 Barkley --> 2079 Gasol --> 2046 LeBron --> 2004 Kobe --> 1960 Pietrus --> 1911 >>> 5. An n-by-n square is magic if a) it contains the integers from 1 to n squared, each integer once b) the sum of all elements on a row, column or diagonal is the same Implement the following procedure to construct magic n-by-n squares; * it works only if n is odd. * Place a 1 in the middle of the bottom row. * After k has been placed in the (i, j) square, place k+1 into the square to the right and down, wrapping around the borders. * However, 1. if the square to the right and down has already been filled, or 2. if you are in the lower right corner, then you must move to the square straight up instead. Here's the 5-by-5 square that you get if you follow this method: 11 18 25 2 9 10 12 19 21 3 4 6 13 20 22 23 5 7 14 16 17 24 1 8 15 Check that the square above is magic. Calculate the 3-by-3, 7-by-7 and 13-by-13 magic squares. Here's how my code is working: >>> ================================ RESTART =================================== Size: 3 4 9 2 3 5 7 8 1 6 >>> ================================ RESTART =================================== Size: 5 11 18 25 2 9 10 12 19 21 3 4 6 13 20 22 23 5 7 14 16 17 24 1 8 15 >>> ================================ RESTART =================================== Size: 7 22 31 40 49 2 11 20 21 23 32 41 43 3 12 13 15 24 33 42 44 4 5 14 16 25 34 36 45 46 6 8 17 26 35 37 38 47 7 9 18 27 29 30 39 48 1 10 19 28 >>> ================================ RESTART =================================== Size: 9 37 48 59 70 81 2 13 24 35 36 38 49 60 71 73 3 14 25 26 28 39 50 61 72 74 4 15 16 27 29 40 51 62 64 75 5 6 17 19 30 41 52 63 65 76 77 7 18 20 31 42 53 55 66 67 78 8 10 21 32 43 54 56 57 68 79 9 11 22 33 44 46 47 58 69 80 1 12 23 34 45 >>> ================================ RESTART =================================== Size: 11 56 69 82 95 108 121 2 15 28 41 54 55 57 70 83 96 109 111 3 16 29 42 43 45 58 71 84 97 110 112 4 17 30 31 44 46 59 72 85 98 100 113 5 18 19 32 34 47 60 73 86 99 101 114 6 7 20 33 35 48 61 74 87 89 102 115 116 8 21 23 36 49 62 75 88 90 103 104 117 9 22 24 37 50 63 76 78 91 92 105 118 10 12 25 38 51 64 77 79 80 93 106 119 11 13 26 39 52 65 67 68 81 94 107 120 1 14 27 40 53 66