5-to-10-minute suggested exercises, April 9-14, CMS.951 (1) Write some code that prints out numbers, counting from 10 to 200 by 10s. *After* you've done this, read the following: There are two or three fairly obvious ways to this. You can use a standard for loop that counts from 0 to 19, then multiply by the result by 10, and then add 10. Of course, if you wrote the loop so that it goes from 1 to 20, you don't need to add 10. And, you don't have to do any manipulation of the value. You can get the range() operator to directly produce a list that begins 10, 20, 30 ... and goes up to 200. If you don't remember how (we only looked at it in class once or twice) just search the Web to learn about Python's range() operator. None of these ways are wrong; some might be cleaner-looking and less error-prone than others. (2) Iterate through a list and double the value of every element. The list should be changed at the end; nothing should be printed. (3) Place your code from (2) in a function called double(). Make sure the function returns a value -- do you know why this is needed? Check that the function works on many different lists. What if the elements of the list are integers? Floating point numbers? Strings? What if the elements of the list are themselves lists? What if different elements are different types? Can you find anything that your function won't double? (4) Remember your tip calculator from last week? Re-write the basic vesion that takes the price of a meal as an argument and computes a tip using a built-in percentage. As before, use 'def' to define it as a function. Then, generalize this so that instead of using a built-in percentage, a second argument is given to specify the tip percentage. Advanced option: Python allows you to define optional arguments, as we saw with the Inscribe class. Make the tip percentage an optional argument so that the built-in percentage is used if a different percentage isn't specified. (5) Write a program that prints either a line of "#" characters or a line of spaces across the terminal at random, as if flipping a fair coin, and continues doing this "forever." (That is, until the program is interrupted by CRTL-C or the computer is shut off.) You will wish to use the "random" module. Also, you'll have to figure out how to have the program loop forever. You will probably wish to use a "while" loop instead of using "for". (6) Modify (5) to produce a pattern more pleasing to you. At least try some computational modifications, rather than just changing the the characters that are used. But if the modification you like involves only changing data, that's fine.