Page 81 - Programming With Python 3
P. 81

An Introduction to STEM Programming with Python — 2019-09-03a                               Page 68
            Chapter 5 — For (Looping)



            3. The Fibonacci Sequence is a progression of integers where the next value is the sum of the previous
             Free
            two values. Create a list with the two numbers 0 and 1. In side a for loop that repeats 20 times, write an
            expression that adds the first two numbers in a list and appends them to the list. Print the new list.

            4. Write a program the will print the factorial for an integer that the user enters. The factorial is the
            product of the integers from 1 to the number entered. Use a for loop to iterate through the integers and
            calculate the product.
             eBook

                                                                                                        -5
                                                                                                             5
            5. Create a program that will use a for statement to create and print a list of powers of 2, from 2  to 2 .
            6. In statistics, the Root mean square (RMS) is also known as the quadratic mean. To calculate the
            RMS we need to create the sum of the squares of a list of numbers, divide the sum by the number of
            elements, and display the square root of the square mean. Write a program that will take a list of
            floating point numbers, assigned to a variable, that calculates and displays the RMS. The formula for
            RMS is:
             Edition √                                 a + a + a + ...a 2 n
                                                                2
                                                            2
                                                        2
                                                            1
                                                                2
                                                        0
                                                              n
            Please support this work at
            7. Given two lists of numbers: [.2, .3, .1, .1, .2, .1] and [1, 2, 3, 10, 5, 7] calculate and display the
            weighted average of the second list using the weights found in the first list. Weighted average is
            defined as the sum of each value times its weight divided by the total of the weights. In this assignment
            the sum of the weights is 1, simplifying your calculations. The formula for Weighted Average is:
                                  http://syw2l.org
                                                            ∑ v ∗w
                                                                     n
                                                                 n
                                                       WA=
                                                              ∑ w
                                                                   n
                                                                               Free
            8. Write a program that will calculate the total selling price of an inventory of items. The items and
            information about each of them are stored in the following dictionary:
                                         {"AA":["Apple Acid", 2, 1.23],
                                      "BB":["Battery Butter", 12, 8.45],
                                      "CZ":["Cubic Zirconia", 8, 4.56],
                                      "DD":["Diamond Dust", 15, 99.56]}
            The Key to the dictionary is the item ID, the list of values contains the items name, the quantity on
            hand, and the current selling price.                   eBook



            Word Search


                                                                Edition









            Copyright 2019 — James M. Reneau Ph.D. — http://www.syw2l.org — This work is licensed
            under a Creative Commons Attribution-ShareAlike 4.0 International License.
   76   77   78   79   80   81   82   83   84   85   86