python05(): Exercises for loops. Evaluate triangular numbers for 0 <= n < 11. t( 0 ) = 0.0 t( 1 ) = 1.0 t( 2 ) = 3.0 t( 3 ) = 6.0 t( 4 ) = 10.0 t( 5 ) = 15.0 t( 6 ) = 21.0 t( 7 ) = 28.0 t( 8 ) = 36.0 t( 9 ) = 45.0 t( 10 ) = 55.0 Repeat calculation, using // for integer division. t( 0 ) = 0 t( 1 ) = 1 t( 2 ) = 3 t( 3 ) = 6 t( 4 ) = 10 t( 5 ) = 15 t( 6 ) = 21 t( 7 ) = 28 t( 8 ) = 36 t( 9 ) = 45 t( 10 ) = 55 Non-indented statements before and after loop. S starts out at 0 t( 1 ) = 1 t( 2 ) = 3 t( 3 ) = 6 t( 4 ) = 10 t( 5 ) = 15 t( 6 ) = 21 t( 7 ) = 28 t( 8 ) = 36 t( 9 ) = 45 t( 10 ) = 55 Sum of triangular numbers is 220 The range statement returns a list of loop indices. range ( 10 ) = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] range ( 0, 10 ) = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] range ( 10, 10 ) = [] range ( 10, 0 ) = [] range ( 10, 0, -1 ) = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] range ( 0, 10, 2 ) = [0, 2, 4, 6, 8] We can use a list instead of range(). UScoins = [1, 5, 10, 25, 50, 100] The sum of a collection of US coins is 191 friends = ['Alice', 'Bob', 'Carol', 'David'] My friend Alice has a name of length 5 My friend Bob has a name of length 3 My friend Carol has a name of length 5 My friend David has a name of length 5 patient0 = ['Robert Baratheon', 235.4, 73, False] patient1 = ['Arya Stark', 134.7, 68, True] patients = [['Robert Baratheon', 235.4, 73, False], ['Arya Stark', 134.7, 68, True]] Robert Baratheon weighs 235.4 lbs and is 73 inches tall. Arya Stark weighs 134.7 lbs and is 68 inches tall. A nested loop allows us to process matrix entries. A = [[0.03757387 0.34131639 0.99354428] [0.3520471 0.94363297 0.15407962] [0.48228158 0.55489399 0.18388203] [0.92389241 0.37971198 0.11977826]] average matrix entry is 0.4555528734472701 While loop for triangular numbers. 1000 <= t( 45 ) = 1035