Exercises: Lists, Loops, Functions

Exercises

  1. Modify the prime number detection program from one of the previous exercises: make the prime number detection a function, and call the function instead. The function (is_prime() is a likely name) takes a number, and returns a boolean value as appropriate.

  2. Write a function uniq() that takes a sequence as input. It returns a list with duplicate elements removed, and where the contained elements appear in the same order that is present in the input sequence. The input sequence remains unmodified.

  3. Write a function join() that takes a string list strings and a string separator as parameter. It joins strings together into a single string, using separator as a separator. For example,

    • join(['Hello', 'World'], '-') returns 'Hello-World'

    • join(['Hello'], '-') returns 'Hello'