80-629 -- Python exercisesThese are meant to complement the python tutorial. In brackets next to each exercise I've indicated which Sections are required to complete the exercise. I suggest using a separate cell for each exercise.
*Bonus*: list every second element in the list. [Section 4] Control statements (loops). Print the sum of the elements in the list you created in the previous exercise. [Section 4] Control statements (loops). Write a function that checks whether a particular input is prime or not. The function should either print "PRIME" or "NOT PRIME". *Bonus*: When your function finds a non-prime member, have it explain to the user why the number is not prime by listing all of its (positive) divisors. [Section 5] Lists. Suggest two different ways for reversing the order of the elements in a list (you can re-use your list of prime numbers from above). [Section 5] Functional programming tools. Using the *Bonus* When printing right-align all numbers. [Section 9] Classes and objects. Create a class that will be used to manipulate prime numbers. Your class should have three functionalities: 1) generate all prime number in a particular range, 2) test the membership of a new number, and 3) print all prime number from a given list. Note you are free to re-use some of the functions that you've created before. Solutions |